php2
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', '1', 0, '/'); //name, value, expire, path echo $_COOKIE['test']; //1 setcookie('test', '', time()-1) //删除cookie(删除test的cookie值)