用session进行登录验证
页面1:
<html>
<title>Login Test</title>
<body>
<?php
if(empty($_POST['user']))
{
?>
<form action="<?php $PHP_SELF ?>" method=POST >
UserName:<input type="text" name="user" />
</br>
Password:<input type="password" name="pwd" />
<input type="submit" />
</form>
<?php
}
else
{
$user=$_POST['user'];
$pwd=$_POST['pwd'];
if($user=="test"&&$pwd=="test")
{
echo "success";
session_start();
$_SESSION['user']=$user;
header('Location:页面2');
}
}
?>
</body>
</html>
页面2:
<?php
session_start();
if(!empty($_SESSION['user']))
{
echo "success";
}
else
{
echo "Login Please!";
}
?>
时间: 2024-09-15 04:58:40