![](/img/trans.png)
[英]how can i extend the cookie expiration time in php everytime i i regenerate the session id?
[英]How to extend cookie expiration time for the users
我有一个一次性登录的网页。 用户登录后,用户名将保存在Cookie中一年。 现在,该Cookie对于用户而言将过期,因为我是一年前创建的网页。
现在,我想将所有访问我页面的现有用户的到期时间再延长一年。 提前致谢。
以下是我用于保存Cookie的代码:
$password = $_POST['password'];
$username = $_POST['username'];
$sql="SELECT * FROM users WHERE username='$username' and password='$password'";
$result=mysql_query($sql);
$count=mysql_num_rows($result);
if($count==1){
// Set cookies. I set my cookies to 1 year
$expires = 60 * 60 * 24 * 365;
setcookie("username", $username, time()+$expires);
// Re-direct to backend
header("location:welcome.php");
} else {?>
<script>alert("Wrong Username or Password!!!");
window.location="index.php";</script>
<?php
}
?>
您应该只保存cookie。 它看起来像这样:
$username = $_COOKIE["username"];
if($user != "")
{
$expires = 60 * 60 * 24 * 365;
setcookie("username", $username, time()+$expires);
}
它将存储现有用户的用户名一年。 希望能有所帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.