开发者

If isset $_SESSION goto this page?

Ok, having trouble here:

I created开发者_JAVA技巧 a login script, so after a person logs in then they will get direted to another page. And also, I have it redirecting them to the login page if they try and access one of those other pages.

My problem is, if a user is logged in and stumbles to the login page again --by accident-- I would like for it to recognize that the user is logged in and redirect them to that next page (which is index2.php) ?? Having troubles :-(

Here is my code so far:

require_once "inc/functions.class.php";
$quickprotect = new functions('inc/ini.php');

if (isset($_SESSION['goAfterLogin'])){
    $goto = $_SESSION['goAfterLogin'];
    unset($_SESSION['goAfterLogin']);
}
else $goto = $quickprotect->settings['DEFAULT_LOGIN_SUCCESS_PAGE'];

if (isset($_POST[username])) {
    if($quickprotect->login($_POST[username], $_POST[password])) header ("Location: $goto");
}

Here is how I store a users session in the functions page

 public function is_logged_in() {
        //Determines if a user is logged in or not. Returns true or false;
            if ($_SESSION['logged_in'] === md5($this->settings[ADMIN_PW])) {
                return true;
            }
            else return false;
        }


You don't mention how you store your users in your session, but something like this should do it for you:

if(isset($_SESSION['user']))
{
    header("Location: index2.php");
    exit;
}

This will check if you have a user in your session, and if so, redirect to index2.php.

You need to change 'user' according to your session key.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜