php2

时间:2022-05-24 06:31:59

session   //将用户的会话数据存储在服务端,通过 session_start()开启session,通过$_SESSION读写session

session_start();    //开启session
$_SESSION['test'] = time(); //通过全局变量$_SESSION,写入一个session
echo "session_id:".session_id(); //显示当前的session_id
echo "<br>"; echo $_SESSION['test']; //通过全局变量$_SESSION,读取一个session unset($_SESSION['test']); //销毁一个session
echo "<br>";
var_dump($_SESSION); //session_id:lpd56n5qsmga006v3ss300sgf4
//1518599397
//array(0) {
//}

cookie  //将数据存储在客户端

setcookie('test', '', , '/');  //name, value, expire, path
echo $_COOKIE['test']; // setcookie('test', '', time()-) //删除cookie(删除test的cookie值)

expire [ɪkˈspaɪə(r)] 失效 (一颗四百二)