[SOLVED]include_once for files @root

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
User avatar
vigge89
Forum Regular
Posts: 875
Joined: Wed Jul 30, 2003 3:29 am
Location: Sweden

[SOLVED]include_once for files @root

Post by vigge89 »

How can I include_once a file which is located in the server root (/) ?
I've tried include_once('/global.php'); but I get the following error:
Warning: main(/global.php) [function.main]: failed to open stream: No such file or directory in J:\Server\htdocs\index.php on line 6

Fatal error: main() [function.require]: Failed opening required '/global.php' (include_path='.;J:\Server\xampp\php\pear'') in J:\Server\htdocs\index.php on line 6
What's wrong?
Thanks in advance.
Last edited by vigge89 on Sun Aug 29, 2004 12:03 pm, edited 1 time in total.
User avatar
wwwapu
Forum Contributor
Posts: 197
Joined: Wed Apr 07, 2004 11:57 am
Location: Turku, Finland

Post by wwwapu »

You should go up-path by ../global.php or something like that
User avatar
vigge89
Forum Regular
Posts: 875
Joined: Wed Jul 30, 2003 3:29 am
Location: Sweden

Post by vigge89 »

wwwapu wrote:You should go up-path by ../global.php or something like that
it isn't possible to load it from the root?
the problem is that im using mod_rewrite for nicer urls, which makes the number of folders from the root be uknown :(
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

As you are already using .htaccess to rewrite, you could also add a

php_value "include_path" ".;/path/to/root" line ;)

Btw, in windows you need to separate them with ; in unix with :
User avatar
vigge89
Forum Regular
Posts: 875
Joined: Wed Jul 30, 2003 3:29 am
Location: Sweden

Post by vigge89 »

problem is that the local (my computers) and remote (vigge.net) server is on different platforms, mine's on win32, while vigge.net is on linux.
User avatar
m3mn0n
PHP Evangelist
Posts: 3548
Joined: Tue Aug 13, 2002 3:35 pm
Location: Calgary, Canada

Post by m3mn0n »

*drive by posting*

Develop on Linux! It's better! :)
User avatar
vigge89
Forum Regular
Posts: 875
Joined: Wed Jul 30, 2003 3:29 am
Location: Sweden

Post by vigge89 »

Sami wrote:*drive by posting*

Develop on Linux! It's better! :)
probably, but I only have 1 computer, and I want to be able to play games and stuff on it too :P
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

Well, on localhost i edit the php.ini....... and at the remote server i use a .htaccess :)
User avatar
vigge89
Forum Regular
Posts: 875
Joined: Wed Jul 30, 2003 3:29 am
Location: Sweden

Post by vigge89 »

alright, thanks :)
User avatar
andre_c
Forum Contributor
Posts: 412
Joined: Sun Feb 29, 2004 6:49 pm
Location: Salt Lake City, Utah

Post by andre_c »

Or you could try this:

Code: Select all

<? include_once $_SERVER['DOCUMENT_ROOT'] . '/global.php'; ?>
Post Reply