PDA

Click to See Complete Forum and Search --> : including files.....how to make it work on all levels


StrangerInBeijing
Oct 25th, 2007, 03:14 AM
I am setting up a new website, that will run on a Win2K3 Server (some other system on the server need windows), so I will be using WAMP.

Not a php pro (yet), but from what I gathered one can set a specific folder to be your "includes" folder, so in any php page you can just say "include("myfile.php") and it does not matter in what directory you are, myfile.php will be included as long it exists.
Am I right, and if so, how do i do this?

Reason for this is that say I create a header for all pages in mysite/include/header.php. In header.php I include another file (say mysite/lang/en.inc). But now header.php cannot be re-used, if it's in a different directory level. (say i use it in a file, two levels deeper it will crash, because ../lang/incshould now be ../../../lang.php)

I'm fairly sure I just missed sth simple so far...this sounds like everyone should address this "issue"

penagate
Oct 25th, 2007, 03:41 AM
ini_set('include_path', 'path/to/includes/directory');

StrangerInBeijing
Oct 25th, 2007, 03:45 AM
thanks P....
Q: 1) Do I set this only once (say in my index.php in the root)
2) The path I have to set it to should be the full directory path (C:/dahdah/blahblah/includes) or the relative path from where is set it (so, if i set it in index, the path should be "include", because the include folder is directly in the root folder)?

penagate
Oct 25th, 2007, 04:24 AM
Set it in any script that is an entry point (e.g. index.php and any other PHP scripts that aren't just includes).
The path should be absolute.