Forum Moderators: coopster
i installed a php zip code script onto a site. the script works fine but im trying to integrate the current header and footer to it. when i copy the header and footer code over it does not find it. the header and footer is in the includes folder. Example footer code is written like this:
<?php require(DIR_WS_INCLUDES . 'footer.php'); ?>
how can i rewrite this so that it can find it? i tried doing this: '../includes/footer.php'
Welcome to WebmasterWorld!
I think:
<?php require $_SERVER['DOCUMENT_ROOT'] . 'includes/footer.php'; ?>
Or something similar should do the trick.
[php.net...]
(Check the user posts.)
Basically, you either need to have the files reside on the same or lower level as the document you are making the request from, or include the full DOCUMENT_ROOT path to the file. (AFAIK)
Include works the same as require, except for the error level, which is why I cited the include documentation...
<?php require(DIR_WS_INCLUDES . 'footer.php'); ?>
In the above line, DIR_WS_INCLUDES is a constant and should be set in a configuration file or at the top of the script.
The reason this is important: constants are a constant for a reason, it's very likely this value is used elsewhere and needs to be properly set.
Somewhere you should find something like this:
define('DIR_WS_INCLUDES','');
If your includes file is in the domain/document root, then T.M.S.'s suggestion will work like so:
define('DIR_WS_INCLUDES',$_SERVER['DOCUMENT_ROOT']);
If the includes directory is somewhere within the root, append it with the path but don't forget to double-quote:
define('DIR_WS_INCLUDES',"$_SERVER['DOCUMENT_ROOT']/path/to/includes");
Should work.
Don't confuse page links ("linking" in your title) with absolute/real server paths. They are different things. It **is** confusing because this does the same thing, whether in a page (hyperlink) or as an include (needs server path:)
../includes/footer.php
It's also a very bad habit to form, or you wind up with slash-dot insanity
../../../../includes/footer.php
For hyperlinks, start at domain root,
/includes/footer.php
for internal script functions, use the server path,
"$_SERVER['DOCUMENT_ROOT']/path/to/includes"
and you will always know "where you are" in the file system, and so will anyone looking at what you are doing.