Forum Moderators: coopster

Message Too Old, No Replies

PHP Includes not working

         

FloridaCodeSlave

1:16 pm on Mar 12, 2008 (gmt 0)

10+ Year Member



Good morning!

I am new to php and decided to convert my html site over to save myself time. I mde my includes file and put the footer/ navigation etc in there and everything is working perfectly except for my press folder. I have a folder with press releases and for the pages in the folder the navigation include won't work. I created another includes file for folder navigation and tried putting ../ but that didn't work. Does anyone know what I'm doing wrong?

Thank you!

vincevincevince

1:21 pm on Mar 12, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Good Morning to Florida from Kuala Lumpur! Welcome to WebmasterWorld...

I firmly recommend always using absolute file references; that means a complete path starting at the root of your server's filesystem.

Frequently, that will mean:
/var/www/html/includes/header.php (for example)

Your 'document root', i.e. the path to the root of your website (not the server) can always by found using:

$_SERVER['DOCUMENT_ROOT']

This means that your includes can be 100% reliably written as:

include($_SERVER['DOCUMENT_ROOT']."/includes/header.php");

In this way, you never need to worry about changing paths and links; it will always find the right place.

FloridaCodeSlave

1:27 pm on Mar 12, 2008 (gmt 0)

10+ Year Member



OH Thank you for the FAST reply! I will give that a try right away!

FloridaCodeSlave

3:13 pm on Mar 15, 2008 (gmt 0)

10+ Year Member



Sorry its taken me so long to try this. I've had a million meetings this week!
I did the following: <?php include($_SERVER['DOCUMENT_ROOT']."/includes/navigation.php"); ?> and got the following error:
failed to open stream: No such file or directory in /www/sites/www.example.com/News/Press/PressArchive.php on line 189. So it's still not finding it.

I've only been working with php for 2 months now so I'm sure I'm making a silly mistake.

Thank you in advance :-)

[edited by: FloridaCodeSlave at 3:15 pm (utc) on Mar. 15, 2008]

[edited by: eelixduppy at 5:55 am (utc) on Mar. 16, 2008]
[edit reason] example.com [/edit]

londrum

8:34 pm on Mar 15, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



put this on any old page, just so you can check where it's actually pointing to
<?php echo $_SERVER['DOCUMENT_ROOT']; ?>
then just add /includes/navigation.php on the end, or whatever. you'll probably find that it's just pointing to a directory above or below where you want, or maybe you've got a slash missing in the url.

it's not a good idea to give out your actual domain plus the directory and file names stored outside of your root on a public website, by the way. the whole point of storing them outside your root is so they are secure. but if someone knows all the names then you're opening yourself to hacking.

FloridaCodeSlave

8:58 pm on Mar 16, 2008 (gmt 0)

10+ Year Member



Thank you so much its working now!