relative paths and require()

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
simonhooper
Forum Newbie
Posts: 2
Joined: Thu Sep 04, 2003 11:44 am

relative paths and require()

Post by simonhooper »

Problem: The production server and development server determine different current directories.

My development directory structure is like:

c:\inetpub\wwwroot\project\main\login.php
c:\inetpub\wwwroot\project\main\errorhandler.php
c:\inetpub\wwwroot\project\library\libone\dbconnect.php

login.php references dbconnect.php thus:
require_once('../library/libone/dbconnect.php');

in turn dbconnect.php references errorhandler.php thus:
require_once('../main/errorhandler.php');
presumably because it is still login.php that is executing, so the current directory is c:\inetpub\wwwroot\project\main.

All hunky-dory..................until I put in on the production server.

login.php references dbconnect.php ok as before.

But the reference in dbconnect.php ro errorhandler.php has to be changed to
require_once('../../main/errorhandler.php');
It seems that on the production server the current directory is determined by the source file that happens to contain the executing function, not the source file called in the first place by the web server.

All offer of clues, help and enlightenment greatfully accepted.
Simon
User avatar
phice
Moderator
Posts: 1416
Joined: Sat Apr 20, 2002 3:14 pm
Location: Dallas, TX
Contact:

Post by phice »

Normally when I do an include() from a file in another folder, all of the links inside that include file (that are include functions as well) are simply added to the path of the parent file. ie:

/page.php // Parent page
/includes/included_page.php // included file

All of the code that's inside the included_page.php is simply pasted into page.php, not executed before it's included. That's the main problem between using windows as your testing machine, and a linux box for your production machine.

Dont even get me started on my phpFF project (Controls all files and folders where placed). That was a horrible task.
Image Image
simonhooper
Forum Newbie
Posts: 2
Joined: Thu Sep 04, 2003 11:44 am

Post by simonhooper »

Thanks for interest.

Both development and production machines are Windows.

Is there a php oncifguration setting that might affect this?

Simon
Post Reply