Php 代码忽略先前成功登录的有效会话
我有一个登录脚本,如果成功,应该检查会话是否存在,如果不存在,则显示登录表单,一旦发布,进行身份验证,如果成功,则设置会话 在我成功发布表单并成功绑定后,返回页面,它将完全忽略会话并显示登录页面 我不知道我做错了什么,条件句的顺序是否有误?我是否应该在测试之前查找会话,以查看表单是否已发布Php 代码忽略先前成功登录的有效会话,php,authentication,session,ldap,forms-authentication,Php,Authentication,Session,Ldap,Forms Authentication,我有一个登录脚本,如果成功,应该检查会话是否存在,如果不存在,则显示登录表单,一旦发布,进行身份验证,如果成功,则设置会话 在我成功发布表单并成功绑定后,返回页面,它将完全忽略会话并显示登录页面 我不知道我做错了什么,条件句的顺序是否有误?我是否应该在测试之前查找会话,以查看表单是否已发布 <? session_start(); // using ldap bind if(isset($_POST['username']) && isset($_POST['passwor
<?
session_start();
// using ldap bind
if(isset($_POST['username']) && isset($_POST['password'])) {
$username = $_POST['username'];
$password = $_POST['password']; // associated password
// connect to ldap server
$ldapconn = ldap_connect("ldap://ldap.server")
or die("Could not connect to LDAP server.");
if ($ldapconn) {
// binding to ldap server
$ldapbind = ldap_bind($ldapconn,$username,$password);
// verify binding
if ($ldapbind) {
echo "LDAP bind successful...";
$_SESSION['valid_username'] = $username;
} else {
echo "LDAP bind failed...";
}
}
} else {
if(isset($HTTP_SESSION_VARS['valid_username'])) {
print 'you are logged in - congrats';
} else {
?>
<h1>Login</h1>
<form method="post" action="<?=$_SERVER["PHP_SELF"]?>">
<p>username: <input type="text" name="username" /><br />
password: <input type="password" name="password" /></p>
<p><input type="submit" name="submit" value="submit" /></p>
</form><?
}
}
?>
登录
检查会话时,请尝试使用$\u会话而不是$HTTP\u会话\u变量