Announcement

Collapse
No announcement yet.

Can You Force PHP Includes in an Article?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • [CMS] Can You Force PHP Includes in an Article?

    I've been trying to get php includes to work for over a year with no luck.Â*I need to put some includes in my articles so I'm able to update certain content across dozens of pages. I've read there is a way to do this using plugins and templates but my understanding is that the template is only good for one specific include, such as a header or footer. I need to be using multiple includes on many different pages.

    As a test, when I put an include in an article and view the page source, it shows the raw php include tag and does not render it in the page.

    Is there a way to "force" php to render in an article? You can have HTML tags render in an article with proper permissions so I don't see why you can't do the same with php.

  • #2
    You need to create a "PHP Direct Evaluation" instead of "Article" if you wish to have php in the article.

    Please don't PM or VM me for support - I only help out in the threads.
    vBulletin Manual & vBulletin 4.0 Code Documentation (API)
    Want help modifying your vbulletin forum? Head on over to vbulletin.org
    If I post CSS and you don't know where it goes, throw it into the additional.css template.

    W3Schools <- awesome site for html/css help

    Comment


    • #3
      As a test, I created a new "PHP Direct Evaluation" content type and put in:

      <?php include("test.php"); ?>

      Same problem with not loading any content with a regular article, but now on the top of the page it gives the error:
      Parse error: syntax error, unexpected '<' in /home/recroni9/public_html/forums/packages/vbcms/item/content/phpeval.php(97) : eval()'d code on line 1

      I'm not knowledgeable in PHP; I only want to use it for the "include" ability which I've been able to do outside of the vB suite.

      Comment


      • #4
        You do not need the <?php ?> tags in the articles since it is assumed you will be putting php into the php direct evaluation page. Just put the php in there. And look at the example there - all output must be assigned to the variable $output:
        PHP Code:
        /**The php code goes here. It can have as much php as you like,
        but it should end with setting the variable $output.
        e.g.
        $something = $somefunction();
        $something2 = $somefunction2();
        ...
        **/
        $output "Hello World<br />"

        Please don't PM or VM me for support - I only help out in the threads.
        vBulletin Manual & vBulletin 4.0 Code Documentation (API)
        Want help modifying your vbulletin forum? Head on over to vbulletin.org
        If I post CSS and you don't know where it goes, throw it into the additional.css template.

        W3Schools &lt;- awesome site for html/css help

        Comment


        • #5
          I appreciate your help and I sort of got it to work. I put in:

          include("../test.php");
          $output = "Hello World<br />";

          and "this works" (the text in test.php) loaded up - problem is, the include loads at the very top of the page and not in the "Hello World" area where I would expect it to be. To give you a better idea of what I'm doing here is a link of a typical page I'm doing:
          http://www.theconsource.com/forums/c...-2009-Overview

          Much of the content on this page is shared across multiple pages like the sidebars and such which is why I want to have these elements referenced with includes instead of having to manually update each and every one.

          Another big problem is that I'm using custom div tags along with additional.css to get everything laid out properly - when I put this in the PHP Direct Evaulation content type it does not recognize the html tags.

          The PHP Direct Evaluation content type seems to be geared more towards things that I'm not trying to do - the vanilla article content type would be perfect if it allowed me to just put includes in there like any regular html tag.

          Comment


          • #6
            I think your test.php uses echo and/or print. You need to pass the output of your test.php to the $output variable so it renders in the correct position (not in the top of the page)
            while(true){
            if(
            $someone->needsHelp() && $i->canHelp()) $post->help();
            if(
            $i->findBug()) $post->bug();
            }

            Comment


            • #7
              Dody I thought the same thing, so I stripped the code down to $output = include("../test.php"); which did the same thing and put the content at the top of the page.

              It's becoming very frustrating that I can't do a simple php include (or any sort of SSI for that matter - I've tried php, javascript, even ajax just a few moments ago) and absolutely nothing will load the content.

              Comment


              • #8
                I tried using the AJAX script on this page, copying the <script> areas into the "headinclude" template and pasting

                <script type="text/javascript">HttpRequest("../test.html")</script>

                in an article, which still does nothing. Before doing so, I tried the script here and pasted it into the "headinclude" template. When I tried saving it out, the page loaded up blank (not giving an error); after waiting a few minutes I manually reloaded the page and the changes I made did not commit.

                Comment


                • #9
                  Recronin, you are doing it the wrong way. $output = include("../test.php") is wrong.
                  You need to use a temp variable to store your echo as a string and bypass it to the output afterwards.

                  Instead of using echo 'what-ever-goes-here'; you should be using $tempVar .= 'what-ever-goes-here';
                  And then pass it to $output = $tempVar;
                  while(true){
                  if(
                  $someone->needsHelp() && $i->canHelp()) $post->help();
                  if(
                  $i->findBug()) $post->bug();
                  }

                  Comment


                  • #10
                    I really don't understand why one must jump through all these hoops for a simple server side include. It's like vbulletin goes out of it's way to make using them impossible. I understand that these can pose security risks, but that's what permissions are for. As a site administrator I should not be limited to what I can do; if I do something foolish on my part and let Joe user execute html/php/etc then that's my own fault. I know what I'm doing enough for a simple php include. If I didn't, then why even allow me the ability to use HTML?

                    As I said, I've tried numerous ways in doing this:
                    - PHP includes: failed
                    - AJAX includes: failed
                    - SSI: failed

                    - JavaScript includes: work
                    - iframes: work
                    The problem with iframes and JavaScript is that these are executed client-side, not to mention in order for the JavaScript includes to work every linebreak must start with "document.write", so as far as I'm concerned these do not work either.

                    Dody I'm not venting to you on this but rather the vbulletin software. I admit that I'm pretty clueless when it comes to scripting/PHP and am unable to get your solution to work. It is however unacceptable when a simple line of code will do the same job without having to do all of these steps. As I've said in the original post, I've spent well over a year (off an on with many hours in between) trying to get some form of an include to work. Having to create plugins and edit templates every time I want to add a unique include defeats the whole purpose of a CMS.

                    Comment


                    • #11
                      So, exactly how is this done?

                      Code:
                      $tempVar = include("justtesting.txt");
                      $output = $tempVar;
                      Places the result on top of the page, above the header (the included file has no php, just HTML).

                      Also, most people's PHP print stuff as they go along. For instance, I have a php file for a contact form where the form changes fields depending on an input variable. Print statements are use to produce parts of the forms as the PHP goes along. How can one put all of that into just a variable (output)?
                      Last edited by malmazan; Mon 14 Nov '11, 12:03pm.
                      Vote for these issues:

                      Comment


                      • #12
                        Originally posted by malmazan View Post
                        So, exactly how is this done?

                        Code:
                        $tempVar = include("justtesting.txt");
                        $output = $tempVar;
                        Places the result on top of the page, above the header.

                        Also, most people's PHP print stuff as they go along. For instance, I have a php file for a contact form where the form changes fields depending on an input variable. Print statements are use to produce parts of the forms as the PHP goes along. How can one put all of that into just a variable (output)?
                        I suggest using the same method we've had php includes in vBulletin for more than 5 years. You would use output buffering functions provided by PHP. Assign the buffer to the $output variable and go from there.
                        Translations provided by Google.

                        Wayne Luke
                        The Rabid Badger - a vBulletin Cloud demonstration site.
                        vBulletin 5 API

                        Comment


                        • #13
                          Originally posted by Wayne Luke View Post
                          I suggest using the same method we've had php includes in vBulletin for more than 5 years. You would use output buffering functions provided by PHP. Assign the buffer to the $output variable and go from there.
                          In someone else needs it, after a few hours of trying and searching I ended up with:
                          Code:
                          ob_start();
                          include("justtesting.txt);
                          $output .= ob_get_contents();
                          ob_end_clean();
                          With all due respect, the CMS is lousy as it does not address basic needs and documentation is hard to find and downright scarce, and the support we get here is very little. You guys manage to really irritate customers.

                          Would that have been that difficult for support to paste here? We are talking basic use of CMS, no modding.

                          Now if I could just find a way to get the included HTML to show correctly with the side widgets in the right places. I guess I need some DIV work which I'll have to spend another few hours to figure out.

                          At this rate I'll be retired by the time I manage to go online with VB4 with CMS.
                          Vote for these issues:

                          Comment

                          widgetinstance 262 (Related Topics) skipped due to lack of content & hide_module_if_empty option.
                          Working...
                          X