PHP Forums Archive

Redirect to mainpage if already logged in

Tags: login, redirect

AngleV posted on 2010-01-22 15:37:04 #

Hi Olaf

This is an amazing script. I noticed that if you are already logged in and type the login page at the url address bar of the explorer the page loads normally.
I think there is not any meaning to this since the user is already logged in.
Instead it should be much more better to redirect the user to main page automatically.

Thank You.

Comments / discussions

Olaf posted on 2010-01-22 15:43:16 #

yes you're right, use:

if (!empty($_SESSION['user'])) {
    header('Location: /yourmainpage.php);
    exit;
}

Put this code at the top of your page (after the includes)

AngleV posted on 2010-01-22 15:48:55 #

Excellent !!!

Thank you Olaf