Forum Moderators: coopster

Message Too Old, No Replies

Help on adding an ERROR around require/include

         

branmh

12:50 am on Jan 3, 2004 (gmt 0)

10+ Year Member



I have this in a small cgi file: Is there a way see if the $script varible is found, if not show a error instead of a 500 error.

I have tried the following codes:

if (!(-e $script) ) {
print "Content-type: text/html\n\n";
print "Error";
exit(0);
} else {
require "$script";

-------------

eval "require '$script'";
print "Couldn't include $script: $@" if $@;

-------------

if (!include("$script")) { include("$error"); }
require("$wxbin_counter");

But both show eror messages

coopster

1:07 pm on Jan 3, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Did you want to do this in Perl or PHP? Looks like Perl to me so we'll give you the Perl version ;) Assuming the $script variable is a filename, I'd say your first option should be working except you haven't closed your if statement:

if !(-e "$script") {
print 'Error';
exit;
} else {
require "$script";
}

I'm not sure this is your problem though...you may want to have a look at your shebang line and/or syntax elsewhere in the script. Quickest way to find the issue is to check your error logs.

If you want to do this in PHP let us know. Otherwise, I'll ask the moderator to move this thread to the Perl Forum. regards -- coopster

branmh

3:32 pm on Jan 3, 2004 (gmt 0)

10+ Year Member



For PHP

coopster

3:54 pm on Jan 5, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Which version of PHP are you running? (You can use phpinfo() [php.net] to find out).

Note: Prior to PHP 4.0.2, the following applies: require() [php.net] will always attempt to read the target file, even if the line it's on never executes.


if (file_exists($script)) {
print 'Error';
exit;
} else {
require $script; // you may want to use include [php.net] here instead.
}