如果isset $ _SESSION转到此页面? [英] If isset $_SESSION goto this page?
问题描述
好,在这里遇到麻烦:
我创建了一个登录脚本,因此一个人登录后,他们将被引诱到另一个页面.而且,如果他们尝试访问其他页面之一,我会将其重定向到登录页面.
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.
我的问题是,如果用户登录后又偶然偶然进入登录页面,我想让它识别出该用户已登录并将其重定向到下一个页面(即index2) .php)??有麻烦:-(
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;
}
这将检查您的会话中是否有用户,如果是,则重定向到index2.php
.
This will check if you have a user in your session, and if so, redirect to index2.php
.
您需要根据会话密钥更改'user'
.
You need to change 'user'
according to your session key.
这篇关于如果isset $ _SESSION转到此页面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!