Simple PHP Include Problem

by 10 replies
12
#programming #include #php #problem #simple
  • I'm not sure if it's the cause of your problem, but you shouldn't have parenthesis around your include path. And you shouldn't have a single dot at the beginning of the include path either.

    If you want to start the include path from the current directory, it should look like this...

    <?php include "directory/file.php"; ?>

    If you want to start it from one directory up, then it should look like this...

    <?php include "../directory/file.php"; ?>

    That said, if all you want to do is have PHP display "Copyright" and the current year, then it would be simpler just to do this instead...

    <?php echo " Copyright " . date("Y"); ?>
    • [ 1 ] Thanks
    • [1] reply
    • Thanks for your reply Brendan T. Yes you are right - I have taken away the parenthesis but I still cannot get it working. My hosting service will not help me on this as it involves code. I will use your other Copyright code
      Regards Alan..
  • is your site really html?
    do you use some kind of cms?
    • [2] replies
    • I just noticed that your home page is an html file. That won't work since you are using php code in the page. That page needs to be index.php instead of index.html (and all other pages that contain php code need to have a .php extension as well).

      If you'd rather not go to the trouble of changing all of your pages to .php (which would also involve changing all of the links that point to those pages), an easier solution would be to simply use Javascript to display the current year...

      <script type="text/javascript">
      var theDate=new Date()
      document.write(theDate.getFullYear())
      </script>

    • Yes I use simple HTML and CSS by hand. Wish I hadn't bothered now that I know a little of the power of PHP, especially for keeping large menus etc....
      • [1] reply
  • <?php include("./directory/file.php"); ?>


    your missing a ;

    that should work.
    • [1] reply
    • The last semi-colon is optional, as long as it's right before the closing ?> php tag. Yet another PHP quirk...
  • Do you think this line of code in the .htaccess file would help?
    AddType application/x-httpd-php .php .html
    • [1] reply
    • Yes, that may work, depending on how your server is configured however. Or else, just change your index.html to index.php. I went to the site you indicated in your first post and "viewed source". I saw the <?php ?> tags show up right in the source code that is being processed by the browser. PHP will never show up in the source code if it is being processed.

      Browsers, when presented with short lines of <?php ?> code, will not display it, since it is not a valid HTML tag. The problem is your code just isn't being processed by the server before it is sent to the browser.

Next Topics on Trending Feed

  • 12

    The last few days Ive spent trying to get a php include to work on the index page of my site. I have a folder with a php file that Im trying to call but it does not show up. Hosting support cannot help me with code, so Ill ask here.