Results 1 to 4 of 4
  1. #1
    Join Date
    Dec 2001

    SSI include vs PHP include

    Ok I'm more familiar with SSI include than php include. This by the way is my first time using php include.

    Now here's the thing, with SSI include I use this:

    <!--#include virtual="/nav.txt" -->

    The /nav.txt pretty much covers all the pages from the root folder down to the various pages inside the different folders.

    The thing I notice with php include is that it's different.

    For the pages in the root folder you can use this:

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

    however if you try this: <?php include("/nav.php");?>

    It don't work. Now if you try this:

    <?php include("nav.php");?> inside the pages inside a sub folder in the root folder that don't work. If you try this <?php include("/nav.php");?> inside the pages inside a sub folder in the root folder that don't work too.
    If you do this: <?php include("../nav.php");?> that will work for the pages inside the sub folders.

    As you can see with SSI all you need is a / in front of the file names to cover all the pages in all the folders. Is there a similar method for php includes? It's kind of annoying for me to be dividing my php includes between <?php include("nav.php");?> and <?php include("../nav.php");?> .

  2. #2
    Join Date
    Sep 2000
    Alberta, Canada
    As SSI is based on Apache it understands "Document Root" and where it starts, PHP does not. For PHP you must use Relative Links or an "absolute Server path" -- which is: /home/username/public_html/whatever

    You might able to get away with:
    <?php include("./nav.php");?> inside the pages inside a sub folder in the root folder, presuming "nav.php" is also in the sub folder. Otherwise, relative linking or absolute Server path would need to be used. - for all your Hosting needs
    Helping people Host, Create and Maintain their Web Site
    ServerAdmin Services also available

  3. #3
    Join Date
    May 2005
    Lakeland, FL, USA
    you can also use PHP's global $_SERVER variables like so:

    PHP Code:
    include($_SERVER['DOCUMENT_ROOT'] . '/nav.php'); 
    Last edited by GS_Josh; 05-11-2005 at 04:31 PM.

  4. #4
    Join Date
    Feb 2003
    Rob hit the nail on the head. When working with PHP, the directory where the script is executed is considered the document root.

    PHP is generally better if you want to do more than just include a page--but if all you're doing is an include, SSI is fine.

    [what I like to do is have a template, and include the content, rather than vice versa. I bet that could solve your problem, too. ]

Posting Permissions

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