开发者

php custom error handling

i have开发者_如何学JAVA a question for you.

on my site i have the following error report level

// PHP errors that will be reported when the script is run.
error_reporting(0);

problem is that when the session times out i get a blank page and the user has to type the address again to go to the main page and log on.

is there a way to embed a link to the above code so when the session times out it will echo a link to the main page?

i tried

// PHP errors that will be reported when the script is run.
error_reporting(0);
echo ("index.php");

with no luck, any ideas?

thank you. :)


Your session checking code should do a HTTP Redirect to your login page if the user's session has expired.

session_start();

// Check if User is logged in
if (!isset($_SESSION['current_user'])) {
    header("Location: http://example.com/login");
    exit;
}

// Code to run when a User is logged in

....


Oh dear.

> error_reporting(0);

Errors should always be reported - but you should set display_errors to 'off' for production systems.

> so when the session times out...

The session timing out will not throw an error. Either it is your code which is triggering the error, or you're talking about the request timing out. (if you hadn't disabled error reporting you might have been able to work this out for yourself).

Stephen has provided an example of how to check for an invalid session state, however throwing errors from your own code is not necessarily a bad thing, as long as you provide a mechanism for catching them - see set_error_handler.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜