Re: HTML if no PHP
| From: | Ernest E Vogelsinger | Date: | Tue, 04 Feb 2003 19:45:52 +0000 |
| Subject: | Re: HTML if no PHP | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-134319@lists.php.net to get a copy of this message | ||
1) Include file not found:
if (file_exists($incfile))
include($incfile);
else
include ($error_html_file);
2) Error in file:
global $php_errormsg;
$php_errormsg = null;
@include($incfile);
$err = $php_errormsg;
if ($err)
echo "The include file $incfile has an error: $err";
The trick is to put an "@" before the include which will hide the error
(even if it's a critical one).
However, in case of a critical error, your script will silently be aborted.
Thus here's a solution to cature these cases:
3) Include and execute capturing critical errors:
$hf = fopen($incfile, 'r');
if ($hf) {
$buffer = fread($hf, filesize($incfile));
fclose($hf);
}
if ($buffer) {
global $php_errormsg;
$php_errormsg = null;
@eval($buffer);
$err = $php_errormsg;
}
The rest goes as above. The "eval" statement will gracefully handle any
critical error that would bring your script to an immediate halt in case of
@include.
HTH :)
----- Original Message -----
From: "Bob Lockie" <bjlockie@lockie.ca>
To: "php-general Mailing List" <php-general@lists.php.net>
Sent: Tuesday, February 04, 2003 6:11 PM
Subject: [PHP] HTML if no PHP
>
> I want to display an HTML page if PHP can't load an include file or
> otherwise has an error or just doesn't work.
> How do I do this?
>
>
> --
> ----------------------------------------
> Sent from Mozilla and GNU/Linux.
> Powered by an AMD processor.
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>