Php 即使在单击“上一步”选项注销后,Bowser也会登录
我使用php和pdo构建了一个登录页面,并正确创建和登录,但在单击“注销”按钮后,如果我再次单击“上一步”,它将再次转到我的页面,该页面仅在登录时显示,我甚至使用了会话,但它甚至没有正常运行Php 即使在单击“上一步”选项注销后,Bowser也会登录,php,pdo,Php,Pdo,我使用php和pdo构建了一个登录页面,并正确创建和登录,但在单击“注销”按钮后,如果我再次单击“上一步”,它将再次转到我的页面,该页面仅在登录时显示,我甚至使用了会话,但它甚至没有正常运行 <?php include('connect.php'); session_start(); if(isset($_POST['logout'])){ { unset($_SESSION['logged_in']); session_destroy(); header("locatio
<?php
include('connect.php');
session_start();
if(isset($_POST['logout'])){
{
unset($_SESSION['logged_in']);
session_destroy();
header("location:index12.php");
}
}
if(isset($_POST['login']))
{
$username = $_POST['username'];
$password = $_POST['password'];
$errflag = false;
if($username == '' and $password == '') {
echo "you must enter username and password";
$errflag = true;
}
if ($errflag == false) {
SignIn($username,$password);
}
}
function SignIn($username,$password){
global $connect;
$search = $connect->prepare("SELECT * FROM users where username =
:username AND password = :password ");
$search->bindParam(':username',$username);
$search->bindParam(':password',$password);
$search->execute();
$count = $search->rowCount();
if($count> 0)
{
$_SESSION['username'] = $_POST['username'];
if(!isset($_SESSION['logged_in']))
header("Location: myfile.php");
}
else{
echo "wron email or password";
}
}
?>
内页的代码为
<?php
echo "welcome to the website ";
echo "congrats you are logged in ";
?>
<html>
<head>
<title>
welcome here</title>
</head>
<body>
<form method ="POST" action = "login.php">
<button name="logout" style="float:right;">logout</button>
</form>
<h1><center>google is one of the best search engine</center></h1>
</body>
</html>
欢迎光临
注销
谷歌是最好的搜索引擎之一
谢谢,我以上述方式更新了,但它不起作用添加一点代码会话_start()在页面的开头
<?php
session_start();
if(isset($_POST['logout'])){
{
unset($_SESSION['logged_in']);
session_destroy();
header("location:index12.php");
}
}
?>
另外,如果尚未在connect.php中启动会话,则必须使用session_start()启动会话强>
<?php
session_start();
include('connect.php');
我不知道如何开始您的课程,但这是一个建议:
我通常编写一个新的_session()函数,如下所示。我更喜欢设置cookie参数,这样我们就可以控制它了
function new_session()
{
$cookieParams = session_get_cookie_params();
session_set_cookie_params($cookieParams['lifetime'], $cookieParams['path'], $cookieParams['domain'], Sessions::SECURED_COOKIES, Sessions::HTTP_ONLY);
session_name('My_Awesome_App');
session_start();
session_regenerate_id();
}
还有一个可以摧毁一切的
function destroy_session()
{
session_unset();
$params = session_get_cookie_params();
setcookie(session_name(), '', time() - 42000, $params['path'], $params['domain'], $params['secure'], $params['httponly']);
session_destroy();
}
您可以找到有关session\u get\u cookie\u params()的文档。
关于session\u set\u cookie\u params()
回到你的例子
使用这个新函数,您应该在页面顶部调用new\u session()
,您的注销应该是这样的
new_session();
if (isset($_POST['logout'])) { {
unset($_SESSION['logged_in']);
destroy_session(); // our new function
header("location:index12.php");
}
}
如何启动会话?请用完整的错误消息更新您的答案!上面的代码已经存在于我的注销页面中,但它不起作用。当我保持start_session()时,它返回fallwoing错误。致命错误:未捕获错误:调用C:\xampp\htdocs\login.php中未定义的函数start_session():3堆栈跟踪:#0{main}在C:\xampp\htdocs\login.php行中抛出它是session\u start()
不是start\u session()
看我的答案@Ramsorry@funillys我没有注意它,但即使在附加了see之后它也不起作用