cookie
setcookie(名称,值,过期时间,有效路径,有效域,安全);
setcookie('username','zhangshuo',time()+3600,'/');
退出cookie:
setcookie('username',null,-3600,'/');
<?phpsetcookie('username','zhangshuo',time()+3600,'/');
<?phpheader("content-type:text/html;charset=utf-8");setcookie('username',null,-3600,'/');
setcookie('userpwd',null,-3600,'/');echo '<script type="text/javascript">alert("退出成功!");window.location="login.php";</script>';
session
开启会话控制
session_start();$_SESSION['username'] = 'wangyufeng';
退出session:
//1,开启会话控制session_start();
$_SESSION['user'] = null;//2,判断cookie['PHPSESSID']是否存在,如果存在就销毁if(!empty($_COOKIE[session_name()])){ setcookie(session_name(),null,-3600,'/');}//3,调用系统销毁session的函数session_destroy();