PHP基础知识(四)——Cookie、Session

   COOKIE

   1 设置cookie

setcookie(name, value, expire, path, domain, secure, httponly);

   2 读取cookie

if(isset($_COOKIE('username'])) $username = $_COOKIE['username'];

   3 删除cookie

setcookie('username', 'Hannah', time() - 2592000, '/');

   SESSION

   1 开启session

session_start();

   2 设置session值

$_SESSION['username'] = 'winstar';

   3 读取session值

$username = $_SESSION['username'];

   4 销毁session

session_destroy();

   5 设置session过期时间

ini_set('session.gc_maxlifetime', 60 * 60 * 24); //设置
echo ini_get('session.gc_maxlifetime'); //读取

相关推荐