PHP scripting error after changing servers

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
ejames13
Forum Newbie
Posts: 1
Joined: Mon Nov 16, 2009 10:06 am

PHP scripting error after changing servers

Post by ejames13 »

I recently moved a PHP website from one web server to another (changed hosting companies). The site is now hosted with GoDaddy, but when I browse to the hyperlink I receive the following error(s):

Warning: require_once(DB.php) [function.require-once]: failed to open stream: No such file or directory in /home/content/00/5180700/html/cms/includes/global.inc.php on line 3

Fatal error: require_once() [function.require]: Failed opening required 'DB.php' (include_path='.:/usr/local/php5/lib/php') in /home/content/00/5180700/html/cms/includes/global.inc.php on line 3

I've spoken with GoDaddy and they assure me it is a problem with the PHP code and not their web server. Please help!

-Eric J
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: PHP scripting error after changing servers

Post by requinix »

include and require proceed according to the current working directory. This is not always the same directory of the currently-executing script.

If /a.php includes /folder/b.php, and b.php includes "c.php", it will look for /c.php, not /folder/c.php.

The most common solution is to use absolute paths like

Code: Select all

include $_SERVER["DOCUMENT_ROOT"] . "/folder/c.php";
That will work regardless of which file is doing the include().
Post Reply