1

i have 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. :)

2 Answers 2

2

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

....
Sign up to request clarification or add additional context in comments.

1 Comment

check for the data you're storing in the session, and if it's not set, use header() to send a "Location" header back to the browser.
0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.