create a default path

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
bladecatcher
Forum Commoner
Posts: 67
Joined: Sat Mar 12, 2005 12:50 am

create a default path

Post by bladecatcher »

G'day All,
Sorry if this is the wrong place.

I somehow want to have a set path to a directory. So in my php code I can refer to say "include($mydir_path . "header.php")" in any script from any directory.

Can I set a permanent global variable $mydir_path = /var/www/mysite/mydir or is there a better way?

Thanking you in anticipation,
bladecatcher

btw, perhaps it can be set in apache??? that would be good? or php.ini etc???
User avatar
Pyrite
Forum Regular
Posts: 769
Joined: Tue Sep 23, 2003 11:07 pm
Location: The Republic of Texas
Contact:

Post by Pyrite »

Yea, in php.in , add your main path to your include_path then you can just include the script by the filename itself
bladecatcher
Forum Commoner
Posts: 67
Joined: Sat Mar 12, 2005 12:50 am

include_path

Post by bladecatcher »

G'day Pyrite,
Thank you for your reply.

I've done a bit of a search which turned up "http://au.php.net/manual/en/function.se ... e-path.php" (the User Contributed Notes are interesting) but let me get this right.

If I rename the relevant scripts I want to "include" to .inc and put them in the "inc" directory then edit php.ini to:

; UNIX: "/path1:/path2"
;include_path = ".:/php/includes"
include_path "/var/www/inc"

php will then prepend that path to *all* .inc files?

tia
bladecatcher
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

no, php will look through the path(s) supplied in the ini during the search for the file.
bladecatcher
Forum Commoner
Posts: 67
Joined: Sat Mar 12, 2005 12:50 am

Post by bladecatcher »

Thanks feyd.

My thought train was hijacked by an poor article that suggested to me that include_path was just for .inc files.

So if php can't find the file (any file) in the current dir, it searches through the include_path.

Can I somehow use that directive in apache's httpd.conf file? perhaps in a <VirtualHost *>
listing?

thanking you in advance,
bladecatcher
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

yes, read up on how to change php configuration in httpd.conf :: http://php.net/configuration.changes
bladecatcher
Forum Commoner
Posts: 67
Joined: Sat Mar 12, 2005 12:50 am

Post by bladecatcher »

Thanks feyd,

Think i'm away with it now. You've been a great help. Sorry if I'm a bit slow on the uptake occasionally 8-)

cheers,
bladecatcher
bladecatcher
Forum Commoner
Posts: 67
Joined: Sat Mar 12, 2005 12:50 am

include_path recursive

Post by bladecatcher »

G'day All,

Is there a way of making the include_path recursive. (i.e look in sub-directories)?

Thanking you in anticipation,
bladecatcher
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

not without passing the child directory information to the include_path.. but why? you can use relative path data with it.
bladecatcher
Forum Commoner
Posts: 67
Joined: Sat Mar 12, 2005 12:50 am

Post by bladecatcher »

G'day feyd,

Thank you, you've been particularly helpful (and patient) to me. Your taking the time to pass on your considerable knowledge is greatly appreciated.

Both relative and absolute paths have their own draw backs depending on the situation.

I'm currently stewing over how best to construct my site as your probably aware. Decisions I make now could save or create a lot of pain further down the track.

For a number of reasons I'm splitting the site up using named subdomains, those links (between) will be absolute others absolute to the server (/var/www/xyz/page.html) others relative.

I'm thinking about having a link building include so that links do not require updating (a labourious task).

Has there been discussion on this? If so could you give me a hint on a search criteria please?

and ... I think you've answered my question.

and ... do you have any comment on my earlier .inc file question?

Thanking you once again,
bladecatcher
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

which are you talking about? Thus far, you have had 4 posts involving .inc.
bladecatcher
Forum Commoner
Posts: 67
Joined: Sat Mar 12, 2005 12:50 am

Post by bladecatcher »

G'day feyd,

<quot>which are you talking about? Thus far, you have had 4 posts involving .inc.</quote>

"What ia an .inc file?"

There was a few replies, none decisive. And my googling didn't work (i'm not good at it).

also

Has a link builder been discussed?

tia
blade
User avatar
Joe
Forum Regular
Posts: 939
Joined: Sun Feb 29, 2004 1:26 pm
Location: UK - Glasgow

Post by Joe »

"What ia an .inc file?"
An include file containing variables, definitions etc.
Post Reply