萬盛學電腦網

 萬盛學電腦網 >> 網絡編程 >> php編程 >> 用session進行登錄驗證

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

copyright © 萬盛學電腦網 all rights reserved