Path variable??

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
jkashu
Forum Commoner
Posts: 45
Joined: Tue Jan 30, 2007 12:00 pm

Path variable??

Post by jkashu »

I need to develop software for use on multiple websites. How do I avoid having to change the inclusion path on ALL pages??

include("$PATH/login.php");

Can I somehow define a path variable for the whole site???

Thanks!
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Re: Path variable??

Post by pickle »

Look into $_SERVER['DOCUMENT_ROOT'] and maybe get_cwd()
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
dajawu
Forum Commoner
Posts: 59
Joined: Fri May 23, 2008 10:16 am

Re: Path variable??

Post by dajawu »

Or if your making a big application that will be distributed like a Forum, you would want to make a settings page that the end user could change a variable. You would then save the path the end user chooses in a file or DB, then pull it up whenever you need it.
jkashu
Forum Commoner
Posts: 45
Joined: Tue Jan 30, 2007 12:00 pm

Re: Path variable??

Post by jkashu »

That's what I was thinking, but doesn't the file with the variables have to be included on every page???
pkbruker
Forum Commoner
Posts: 32
Joined: Sun Aug 03, 2008 9:36 am
Location: Oslo, Norway

Re: Path variable??

Post by pkbruker »

I've used this technique several times:

1. Make some sort of settings file (i.e. config.inc.php), and make sure it's always included no matter which page is displayed.
2. Decleare this in config.inc.php:

Code: Select all

DEFINE("INCLUDE_PATH","the/path/yeah/");
3. When including other stuff, do like this:

Code: Select all

require INCLUDE_PATH.'the_included_file.php';
Voila! And, you will most surely need more setting variables, which you can decleare in config.inc.php (i.e. mySQL username, password).
Post Reply