I am trying to put together a web site using some basic PHP code. This is the first time I've done PHP so I'm taking my time, but I need some help with include files.
Here is the scenario:
In the main directory of my website I have the index.php (ofcourse) along with a lot of sub-directories.
One of these sub directories I have named "zz_include" and I want this directory to house all the include files for my web site.
As far as the index.php goes, all I have to do it for the include file is --
[PHP]<?php include("/zz_include/header.php"); ?>[/PHP]
and it works fine and dandy.
However, in a sub directory. For example, an "About" page in a directory called "about" I have to back step the include code like so:
[PHP]<?php include("../zz_include/header.php"); ?>[/PHP]
for it to work.
In an ASP setting I can do a virtual include and it will start from the highest directory in the site and find the zz_include directory.
So how can I set up my php site so that I can have one consolodated directory for my includes and use the same string of code to link to them no matter where the page is located? (So if the page is 3 levels deep I dont have to ../../..)
BNet • magicprime#1430 | PSN/Steam • MagicPrime | Origin • FireSideWizard
Critical Failures - Havenhold Campaign •
August St. Cloud (Human Ranger)
Posts
a) Add your document root to your include_path in php.ini/.htaccess/etc.
b) Include the following line at the top of your scripts:
Then if you have say in your websites root directory a folder called inc, you can include('inc/File.php') and you're set.
You are running php in some kind of chroot or secure environment? Because the root directory is supposed to be the host operating system's root (C:\ under windows, / under unix). Not really relevant to this problem, but with a default php config, "/zz_include" would be equivalent to "C:\zz_include\".
You may be able to accomplish what you want by looking at the $_SERVER variable. This will reveal the path configured in httpd for the 'base' directory of the website. So, something like:
Should get you the path you want for any script.
Awesome.
Since I don't have direct access to the web server to do any editing or re-adjusting of the settings. That code string has solved my problems. Thanks a ton!
Critical Failures - Havenhold Campaign • August St. Cloud (Human Ranger)