因此,我正在开发一个应用程序,它要求用户在访问任何“敏感材料”之前必须先登录。
登录脚本的工作原理如下:用户输入U/P->脚本验证数据->如果有效,则设置会话变量。
这是一个非常奇怪的问题,因为会话是由服务器处理的。
问题:当第一次在新窗口或选项卡中打开脚本时,提交登录表单会将您直接带回登录表单。所有后续请求都按预期工作!
有什么想法吗?
发布于 2010-02-13 07:13:59
$5表示$auth->userAuth()是设置会话值的地方,并猜测“密码不匹配”的情况下应该是!$auth->userAuth()。不过,逻辑本身还是有些重叠的。
尝试这样做,只需将逻辑排序到单独的块中:
if ($action == 'login') {
// all of the pre-authentication error checking first
if (!$auth->emailExists($username)) {
header('Location: index.php?action=unknownuser');
} else if (!$auth->isAccountActive($username)) {
header('Location: index.php?action=inactive');
}
// then actual authentication here - any errors have already redirected
$_SESSION['loggedin'] = $auth->userAuth($username, $password);
// opinionated bonus: adds clarity & keeps superglobals out of your classes
// (you'll have to take them out yourself though)
// and finally redirect on success/failure
if (!$_SESSION['loggedin']) header('Location: index.php?action=authfailed');
else header('Location: services.php');
}https://stackoverflow.com/questions/2255371
复制相似问题