当前位置:编程学习 > php >>

用session进行登录验证

用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!";
}
?>

补充:Php教程,Php入门
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,