简体   繁体   中英

PHP require_once not working on Linux

I've transferred a PHP web-system from a Windows hosting provider to a Linux based hosting service.

In the system's scripts, when it comes to require_once , the script simply stops and leaves the user at a blank white page.

I've tried both of the below:

Try 1

require_once($_SERVER['DOCUMENT_ROOT'] . '\library\data\Dbec.php') or die("could not load file");

Try 2

require_once(dirname(__FILE__) . '/library/data/Dbec.php') or die("could not load file");

In both cases, the text in the die parenthesis is not showing and the page remains blank. The script that is requiring the above files is in ' /library/membership/theScript.php '

Based on the reading I've done on line up to now, maybe it has to do with changing the include_path in php.ini file or writing the paths in a different way.

If its any of the above, or something different, I'd appreciate some hints.

Check your error log, to see if anything is visibly wrong. Also try setting error_reporting = E_ALL , and make sure display_errors = On and log_errors = On in your php.ini.

Your file your trying to include is in '/library/membership/theScript.php', try doing:

require_once '../data/Dbec.php';

This isn't going to do what you want. Everything after require_once is being interpreted as a conditional . It's running ($_SERVER['DOCUMENT_ROOT'] . '\\library\\data\\Dbec.php') or die("could not load file") and returning 1 , then running require_once 1 .

To make it work as you expect, you would need an extra set of parentheses:

(require_once($_SERVER['DOCUMENT_ROOT'] . '\library\data\Dbec.php')) or die("could not load file");

Although, I'm not certain the die() will ever get called. It's up to you to figure out.

See this related bug report which was ruled "not a bug."

Also problem can be in file permissions and filename. Windows filesystem is caseinsesetive but linux is not. So you have to check the filename and the fact that user who executes this script has read persmission on the file you try to include with require_once

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM