会话控制 COOKIE SESSION

cookie

setcookie(名称,值,过期时间,有效路径,有效域,安全);

setcookie('username','zhangshuo',time()+3600,'/');

退出cookie:

setcookie('username',null,-3600,'/');

<?php
setcookie('username','zhangshuo',time()+3600,'/');

<?php
header("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();



你可能感兴趣的:(session,cookie)