我有两个脚本,一个用于处理登录,一个用于注册登录,它们都创建一个 sessiod id 并将其插入到 cookie 和数据库中。数据库插入工作得很好,但是没有设置 cookie:
登录:
//...Stuff...
$sql = "SELECT * FROM dm_users WHERE username = '$username' LIMIT 1";
$res = mysql_query($sql);
if(mysql_num_rows($res) == 0) {
header("Location: denied.php?u");
die();
}
while($r = mysql_fetch_assoc($res)){
$brought = $r['password'];
}
if (PassHash::check_password($brought, $password)) {
if($remember == 1) {
$time = time() + (10 * 365 * 24 * 60 * 60);
} else {
$time = 0;
}
$val = uniqid() . time();
setcookie("dmsesid",$val,$time);
$sql = "INSERT INTO dm_sessions (username,sesid,`timestamp`) VALUES ('$username','$val',now())";
$r = mysql_query($sql);
$sql2 = "UPDATE dm_users set lastlogin = NOW() WHERE username = '$username'";
$r2 = mysql_query($sql2);
header('Location: ../characters.php');
} else {
//...More stuff...
注册过程的工作方式大致相同,但只有 $time = 0; 选项。
任何帮助将不胜感激!