Php 登录/注销无法正常工作 您已登录 添加属性:
您可以使用错误的凭据登录,因为PHP不会在单引号字符串中展开变量。您需要使用:Php 登录/注销无法正常工作 您已登录 添加属性:,php,login,logout,Php,Login,Logout,您可以使用错误的凭据登录,因为PHP不会在单引号字符串中展开变量。您需要使用: <?php session_start(); ?> <!DOCTYPE html> <html> <body> <?php $user='hassan'; $apple ="6217c55b626e7477b972034993b40a29"; $salt="231**6"; $uname= $_POST["uname"]; $pas= $_POS
<?php
session_start();
?>
<!DOCTYPE html>
<html>
<body>
<?php
$user='hassan';
$apple ="6217c55b626e7477b972034993b40a29";
$salt="231**6";
$uname= $_POST["uname"];
$pas= $_POST["psw"];
$token1= hash("ripemd128", '$salt$pas');
if($token1===$apple && $user===$uname)
{
$_SESSION["user"]= $user;
echo $_SESSION["user"];
if ($_SESSION["user"] == $user && $token1===$apple )
{
echo "Welcome ".$_SESSION["user"];
}
?>
<h1>you are logged in</h1>
<form action="inbox.php" class="boxed" style ="border: 4px solid black ; text-align: center; method="post">
<h1><b>Check inbox :</b></h1>
<input type="submit" class="button" value="Inbox" style =" background-color: grey;
border: none;
color: white;
padding: 15px 70px;
margin: 15px 0px;
cursor: pointer;"><br><br>
</form>
<form action="add.php"class="boxed" style ="border: 4px solid black ; text-align: center; method="post">
<h1><b>ADD propert :</b></h1>
<input type="submit" value="ADD" style =" background-color: grey;
border: none;
color: white;
padding: 15px 70px;
margin: 15px 0px;
cursor: pointer;">
</form>
<form action="logout.php" class="boxed" style ="border: 4px solid black ; text-align: center; method="post">
<h1>logout here</h1>
<input type="submit" class="button" value="Logout" style =" background-color: grey;
border: none;
color: white;
padding: 15px 70px;
margin: 15px 0px;
cursor: pointer;">
</form>
<?php
$_SESSION["user"]= "null";
$token=null;
$user=null;
}
else
{
?>
<h1>You entered wrong details please enter again</h1>
<a href="admin.html">try again</a>
<?php
}
?>
</body>
</html>
或
简化示例:
ETA注销:
html包含一个链接到单独脚本(logout.php)的按钮。您需要将会话id传递给该文件(读取更多),然后销毁会话
如果$\u会话[“用户”]=“空”;。。。在您发布的代码中,应该将用户注销。没有。当提供了正确的pwd并且根本没有连接到按钮时,我就会被执行
注销脚本运行后,您可以也应该考虑CSRF,但我认为这是以后的一个想法。您怎么可能使用错误的详细信息登录?此代码仅针对一个用户设置。感谢您的帮助,并请建议如何在注销时结束会话!
hash("ripemd128", "$salt$pas");
hash("ripemd128", $salt.$pas);