gpt4 book ai didi

javascript - 注销并按后退按钮后,同一页面将在 PHP 中显示

转载 作者:行者123 更新时间:2023-12-01 02:03:30 25 4
gpt4 key购买 nike

我正在使用带有 session 的 php。注销后,它重定向到登录页面,但按后退按钮后,它再次向我显示未登录的页面。我怎么解决这个问题。提前致谢

index.php

<form style="padding-left: 50px; padding-right: 50px;" action="func.php" method="post">
<label for="uname" style="color:white;"><b>Username</b></label>
<input type="text" placeholder="Enter Username" name="uname" style="border-radius: 10px;" required>

<label for="psw" style="color:white;"><b>Password</b></label>
<input type="password" placeholder="Enter Password" name="psw" style="border-radius: 10px;" required>

<button type="submit" name="login_submit" class="b1">Login</button>
</form>

func.php

<?php                                                        
session_start();
$con=mysqli_connect("localhost","root","","forestdb");
if(isset($_POST['login_submit'])){
$username=$_POST['uname'];
$password=$_POST['psw'];
$query="select * from login where username='$username' and password='$password';";
$result=mysqli_query($con,$query);
if(mysqli_num_rows($result)==1)
{
$_SESSION['username']=1;
header("Location:create_journal.php");
}
else{
echo "<script>alert('Enter Correct Details!!')</script>";
echo "<script>window.open('index.php', '_self')</script>";
}
}
?>

创建_journal.php

<li><a href="logout.php" style="color:white;"  onmouseover='this.style.color="#08367f"' onmouseout='this.style.color="white"'><span class="glyphicon glyphicon-log-out"></span> Logout</a></li>

注销.php

<?php                                                        
session_start();
session_destroy();
header("Location:index.php");
?>

最佳答案

首先,您的代码非常容易受到 SQL 注入(inject),请使用 prepared statements并阅读所说的here .

其次,您似乎没有检查 $_SESSION['username'] 是否已设置,这意味着,如果您知道要访问的网址,则可以访问页面而无需登录,这反过来意味着您可以返回一页,您将看到完全相同的内容。

关于javascript - 注销并按后退按钮后,同一页面将在 PHP 中显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50313199/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com