这是一个简单的用户名/密码登录表单。当我提交正确的数据时,它会转到 test.php 并回显 'hi' 。但是,如果我在 test.php 上点击刷新,它会显示没有权限。提交后刷新 test.php 后,如何让它在 test.php 上显示“hi”?
登录.php:
<?php
session_start();
session_unset();
?>
<html>
<body>
<?php include 'header.php'; ?>
<form action = "test.php" method = "post">
<br/>
Enter username
<input type = "text" name = "user"/>
<br/>
Enter passowrd
<input type = "password" name = "pass"/>
</br>
<input type = "submit" value = "submit" name = "submit"/>
</form>
</body>
</html>
测试.php:
<?php
session_cache_limiter('private_no_expire');
session_start();
$_SESSION['authuser'] = 0;
if(isset($_POST['user']) && isset($_POST['pass']))
{
$_SESSION['username'] = $_POST['user'];
$_SESSION['userpass'] = $_POST['pass'];
}
else
{
$_SESSION['username'] = NULL;
$_SESSION['userpass'] = NULL;
}
if($_SESSION['username']=="joe" && $_SESSION['userpass'] == 123456)
{
$_SESSION['authuser']=1;
echo 'hi';
}
else
{
echo "No permission";
exit();
}
?>