如果设置 $_SESSION 转到此页面?

发布于 2024-10-14 06:12:36 字数 948 浏览 0 评论 0原文

好的,这里遇到麻烦:

我创建了一个登录脚本,因此在一个人登录后,他们将被定向到另一个页面。而且,如果他们尝试访问其他页面之一,我会将其重定向到登录页面。

我的问题是,如果用户登录并再次偶然进入登录页面,我希望它能够识别用户已登录并将其重定向到下一页(即index2.php) ??有麻烦:-(

这是到目前为止我的代码:

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");
}

这是我在功能页面中存储用户会话的方式

 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;
        }

Ok, having trouble here:

I created 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;
        }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

躲猫猫 2024-10-21 06:12:36

您没有提到如何在会话中存储用户,但是类似这样的事情应该为您做:

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

这将检查您的会话中是否有用户,如果有,则重定向到 index2.php.

您需要根据您的会话密钥更改'user'

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文