我有一个网站,想要通过选中框来记住会话。
我有一个代码来记住用户名和密码,但是当我重新启动浏览器时它无效。
以下是代码:
session_start();
session_regenerate_id();
$_SESSION['id'] = $id;
$_SESSION['mdid'] = $mdid;
$_SESSION['start'] = $start;
$_SESSION['firstname'] = $firstname;
$_SESSION['lastname'] = $lastname;
$_SESSION['username'] = $username;
$_SESSION['email'] = $email;
$_SESSION['password'] = $password;
$_SESSION['country'] = $country;
$_SESSION['city'] = $city;
$_SESSION['joined'] = $joined;
$_SESSION['activation'] = $activation;
$_SESSION['banned'] = $banned;
$_SESSION['ckey'] = $ckey;
// these above variables are from database.
$ctimee = time();
$ckeyy = rand(100000,999999);
mysql_query("UPDATE users SET ckey='$ckeyy', ctime='$ctimee' WHERE id='$id'");
$remember = $_POST['remember'];
if($remember){
setcookie("id", $_SESSION['id'], time()+60*60*24*COOKIE_TIME_OUT, "/");
}
答案 0 :(得分:1)
setcookie("id", $_SESSION['id'], time()+60*60*24*COOKIE_TIME_OUT, "/") or die("Session writing error");
如果您收到错误,则需要将代码放在文件开头。