源来页 公告 登陆

PHP教程之session和cookie

composer @Ta
2016-05-28 20:55

存储和取回 session 变量的正确方法是使用 PHP $_SESSION 变量:

<?php
session_start();
// store session data
$_SESSION['views']=1;
?>

<html>
<body>

<?php
//retrieve session data
echo "Pageviews=". $_SESSION['views'];
?>

</body>
</html>

unset() 函数用于释放指定的 session 变量:
<?php
unset($_SESSION['views']);
?>

setcookie() 函数用于设置 cookie。
注释:setcookie() 函数必须位于 <html> 标签之前。
语法
setcookie(name, value, expire, path, domain);

<?php 
setcookie("user", "Alex Porter", time()+3600);
?>
//取出cookie
<?php
// Print a cookie
echo $_COOKIE["user"];

// A way to view all cookies
print_r($_COOKIE);
?>
//注销
<?php 
// set the expiration date to one hour ago
setcookie("user", "", time()-3600);
?>
阅:2148 发表于2016-05-28 20:55
#php教程
评论:

返回源来页/返回首页


天合之作 曲在人意

心灵鸡汤:
      

®2019-2024 all power by Zlproject3.7
川公网安备 51192202000151号
蜀ICP备2021014921号-2 首页 #top

本网站由提供CDN加速/云储存服务

天合之作 曲在人意