本文实例讲述了PHP会话控制。分享给大家供大家参考,具体如下:
关于cookie和session的测试代码:
session_start();
define('u','a');
define('p','1');
if(isset($_GET['r']) &&$_GET['r']== 1) {
unset($_COOKIE['username']);
unset($_COOKIE['password']);
unset($_SESSION['valid_login']);
}
if(isset($_POST['username']) && isset($_POST['password'])) {
$username=$_POST['username'];
$password=$_POST['password'];
if($username== u &&$password== p) {
$_SESSION['valid_login'] = 1;
setcookie('username',$username);
setcookie('password',$password);
}else{
echo'incorrect u or p';
}
}
?>
|