[英]php login and logout using session
I'm trying to create a login page but I'm facing an issue with the session variable My code : login.php我正在尝试创建一个登录页面,但我遇到了会话变量的问题我的代码: login.php
<?php
require('DBConnect.php');
session_start();
if(isset($_SESSION['status'])){
header("location: index.php");
exit(0);
}
?>
index.php索引.php
<?php
session_start();
$user = $_SESSION['user'];
if(!isset($_SESSION['status'])){header("location: login.php");}
?>
logout.php注销.php
<?php
session_unset();
session_destroy();
header("location: login.php");
exit(0);
?>
When I go to the logout page, the page is redirected to login.php but it redirects also again to index.php whcih means that $_SESSION['status']
is set I'm only setting these Session variables when the POST request is sent, is there anything wrong here?当我进入注销页面时,该页面被重定向到 login.php 但它也再次重定向到 index.php 这意味着
$_SESSION['status']
已设置我仅在 POST 请求时设置这些 Session 变量已发送,这里有什么问题吗? Thanks in advance提前致谢
您需要将session_start()
添加到 logout.php 代码的开头。
You have a logic flaw in your code.您的代码中存在逻辑缺陷。 logout.php ends the session and redirects you to login.php, but login.php starts a new session which is why it then redirects you again to index.php.
logout.php 结束会话并将您重定向到 login.php,但 login.php 会启动一个新会话,这就是为什么它会再次将您重定向到 index.php。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.