REQUIRE ONCE CONTRADICTION

How to go nuts …
Reconstructing a years-in-service PHP4 Registration page for my web site to PHP5, and find this contradiction:

Early in the script, L. 41: require_once $_SERVER[‘DOCUMENT_ROOT’]."/cnnct2mysql.php";

  1. Running script from unix, php RGSTRTN_07_7a.php, throws following error;

PHP Warning: require_once(/cnnct2mysql.php): failed to open stream: No such file or directory in /home/…/RGSTRTN_07_7a.php on line 41
PHP Fatal error: require_once(): Failed opening required ‘/cnnct2mysql.php’ (include_path=’.:/usr/share/php:/usr/share/pear’) in /home/vg010web02/68/65/2926568/web/auxlib/web07/HTMLpages…/RGSTRTN_07_7a.php on line 41

But require_once $_SERVER[‘DOCUMENT_ROOT’]."/cnnct2mysql.php", has the correct address.

  1. Running script from Mozilla Firefox, www.u-sit.net/.../ RGSTRTN_07_7a.php, throws no error. None recorded in error log. The script runs up to the registration form for a customer to fill in, accepts in put to the form, then (presumably) posts form to PayPal sandbox. However, it runs no further and throws no error; hence, no hint of where to look next.

What does this apparent contradiction mean? Unix doesn’t get past the compiler. In case (2.) the compiler does not stop the script.

ANY SUGGESTIONS WOULD BE APPRECIATED

THNX
usit

My guess is this. You are using a forward slash ‘/’ in your path. That is fine for web, but on the server it is looking local so you should switch to a backslash ‘’. Or you can use the DS constant to make sure it is always right:

require_once $_SERVER[‘DOCUMENT_ROOT’].DS.“cnnct2mysql.php”;

try that.

When you run a PHP script from the command-line or through cron, [tt]$_SERVER[‘DOCUMENT_ROOT’][/tt] does not exist. This value is only defined when PHP is run through a web-server. If you look at the error message:

[tt]PHP Warning: require_once(/cnnct2mysql.php): failed to open stream:[/tt]

You can see that it has no value, (which PHP interprets as an empty string), so you are trying to include a file from the filesystem’s root.

Why are you trying to run a registration script from the command-line? — Or did I misunderstand completely?

Sponsor our Newsletter | Privacy Policy | Terms of Service