Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => General

Stupid include path

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

Stupid include path

Postby Xerpher » Tue Sep 10, 2002 4:37 pm

I cant believe I have to ask this, but everytime I try to include another php file thats not in the same directory it gives me an include_path error, so I have to put the long directories in every include string, is there a way I can just set one variable so I never have to worry about it again?
Xerpher
New php-forum User
New php-forum User
 
Posts: 164
Joined: Tue Aug 27, 2002 8:25 pm
Location: Ontario, Canada

Postby lacroix13 » Tue Sep 10, 2002 11:37 pm

To go a higher level into the directory tree, you must use "..//"
That is you have:
directory DIR with subdirs SUB1 and SUB2 and you want to include in a file x.php from SUB1 a file y.php from SUB2 you must use: include("..//SUB2/y.php").
You can set a variable with this path.
User avatar
lacroix13
New php-forum User
New php-forum User
 
Posts: 64
Joined: Thu Aug 22, 2002 1:07 am

Postby Jay » Wed Sep 11, 2002 12:05 pm

The way I do it to always use the full root path eg /home/yoursite/the/full/path

But to make it easier I made up one script which held the path for every single page, like so:
$base = "/home/yoursite/";
$terms = $base."terms/term.php";
$sales = $base."sales.php";
etc

Anyway, then on each script, you have this code at the very top:
require_once("/home/yoursite/where/that/file/was");
and then you can include whatever pages you want by refering to their name eg include($terms) etc
Jay
 

Postby Xerpher » Wed Sep 11, 2002 3:19 pm

Yea ok, I was hoping I could do something to never have to worry about it again :) but I think I'll do something similar to what you said Jay.
Xerpher
New php-forum User
New php-forum User
 
Posts: 164
Joined: Tue Aug 27, 2002 8:25 pm
Location: Ontario, Canada


Return to PHP coding => General

Who is online

Users browsing this forum: No registered users and 2 guests

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.