[英]Logout automatically after 1 minutes using php
I am creating a simple login page using session and cookie.我正在使用 session 和 cookie 创建一个简单的登录页面。 If the user login on system and if the user don't do anything on the page,it will redirect to login page again after 1 minutes using php What I have tried so far is attached below.
如果用户登录系统并且用户没有在页面上执行任何操作,它将在 1 分钟后使用 php 再次重定向到登录页面 我到目前为止所尝试的内容附在下面。
Login.php登录.php
<?php
session_start();
if ($_SERVER['REQUEST_METHOD'] == 'POST'){
$username = $_POST['uname'];
$password = $_POST['pass'];
if($username == "kobi" && $password == "123"){
$_SESSION["uname"]=$username;
setcookie("user", $username, time() + (60));
header('location:welcome.php');
}
}
?>
welcome.php欢迎。php
<?php
session_start();
echo "User Name " . $_SESSION['uname'] . ".<br>";
?>
I think you should change the setcookie time function.我认为您应该更改 setcookie 时间 function。
as your function was因为你的 function 是
setcookie("user", $username, time() + (60));
So remove the time second as round brackets所以删除时间秒作为圆括号
setcookie("user", $username, time() + 60);
Hopefully this works.希望这有效。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.