Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6

Thread: PHP Include

  1. #1
    New Coder
    Join Date
    Jul 2012
    Posts
    13
    Thanks
    3
    Thanked 3 Times in 3 Posts

    Question PHP Include

    PHP include feature wont work for me,

    I have tried:
    Code:
     <?php
     require($DOCUMENT_ROOT . "path to file/include-file.html");
     ?>
    And Also:

    Code:
     <?php include 'header.php'; ?>
    I'm not sure if it is XAMPP or the code.
    The code also did not work on X10 hosting.
    Any suggestions?

    Thanks

  • #2
    New to the CF scene
    Join Date
    Jul 2012
    Posts
    4
    Thanks
    0
    Thanked 1 Time in 1 Post
    Quote Originally Posted by alex11 View Post
    PHP include feature wont work for me,

    I have tried:
    Code:
     <?php
     require($DOCUMENT_ROOT . "path to file/include-file.html");
     ?>
    And Also:

    Code:
     <?php include 'header.php'; ?>
    I'm not sure if it is XAMPP or the code.
    The code also did not work on X10 hosting.
    Any suggestions?

    Thanks
    Perhaps header.php doesn't exist in the same directory as the file you are calling it from. Either way, try using header.php's absolute path.

  • #3
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    27,206
    Thanks
    80
    Thanked 4,566 Times in 4,530 Posts
    Not to ask a silly question... are you sure that PHP is working, at all, for you?

    Can you do something as simple as
    Code:
    <?php
    echo "This PHP test worked.<hr/>\n";
    ?>
    ???
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • Users who have thanked Old Pedant for this post:

    alex11 (07-17-2012)

  • #4
    New Coder
    Join Date
    Jul 2012
    Posts
    13
    Thanks
    3
    Thanked 3 Times in 3 Posts

    Thank You

    Thank you for the tip.
    The php code would not work in my header.html file, but it needs to be in a php document of its own.
    Will all of my pages need to be php or is there a way to have php in html

  • #5
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    You can modify the httpd.conf or .htaccess to issue an addtype for the php interpreter.
    PHP Code:
    AddType application/x-httpd-php .html 
    You can also use rewriting to force specific files if you want.

    Edit:
    BTW, for your original post, $DOCUMENT_ROOT hasn't been declared anywhere. This may be a part of the $_SERVER Superglobal, but don't rely on its existence in the form of $DOCUMENT_ROOT (or even in the $_SERVER superglobal for that matter), as it will only exist in a register_global environment (which is gone as of 5.4), and disabled by default since 4.2.

  • #6
    Senior Coder
    Join Date
    Jun 2008
    Location
    New Jersey
    Posts
    2,542
    Thanks
    45
    Thanked 259 Times in 256 Posts
    Yah, by default, a server will only process files it knows to process, eg, a PHP processor will only process files ending with .php, so it won't look at ASP files or similar and try to figure them out (likely throwing a fatal error in the process). As Fou said, you can either tell your system to process HTML files through the PHP processor, or you can just rename your html files to .php. HTML is a plaintext format, so PHP won't be bothered by files with no PHP tags in them.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •