php inlcude path problem (I think)

php inlcude path problem (I think)

Posted by: OriginalMacBabe
Posted on: 2007-05-24 14:08:00

I am trying to use php include to add header, footer, and navigation to my site.

I used this code:

In reply to:


<div id="main_nav">
<?php include("../includes/main-nav.php";) ?>
</div>


but I got this when I tried to load my page:


In reply to:

Parse error: syntax error, unexpected T_STRING in /home/.sada/ellen/ellenseyes.com/index.php on line 1


I am thinking that it just doesn't know where to find my files. I tried having them in the same directory, and specifying the directory with a full path, but the error message remains the same.

I don't know what the ".sada" is, but since it is above the level of my sites's directory, I'm guessing that the include function is looking for my files too high in the structure.

How am I to correctly specify my include files, which I want to house in a directory named "includes"?

What have I done wrong?

Re: php inlcude path problem (I think)

Posted by: scjessey
Posted on: 2007-05-24 15:27:00

You have a syntax error (a semicolon is in the wrong place), but there is an easier way to do it anyway. Assuming that your "includes" folder is your web root (ellenseyes.com/includes), use this code:

<?php include($_SERVER['DOCUMENT_ROOT']."/includes/main-nav.php"); ?>

You can put that on any page of your site, in any directory, and it will always work.

Re: php inlcude path problem (I think)

Posted by: OriginalMacBabe
Posted on: 2007-05-24 16:18:00

Thank you scjessey

I had already corrected the syntax error.

That works exactly as it should.

Re: php inlcude path problem (I think)

Posted by: anonymous2
Posted on: 2007-05-24 16:23:00

<joke> Obviously you do not consistently spell "inlcude" correctly. ;-)

Re: php inlcude path problem (I think)

Posted by: scjessey
Posted on: 2007-05-24 18:34:00

In reply to:

Obviously you do not consistently spell "inlcude" correctly


Obviously you do not consistently construct sentences correctly. smile

Re: php inlcude path problem (I think)

Posted by: OriginalMacBabe
Posted on: 2007-05-24 21:45:00

Geez! You have no idea how long it took me to find the typo. I looked through the entire thread ...

Tags: path problemphp includereply