返回列表 发帖

PHP Cookies

cookie 常用于识别用户。

什么是 Cookie?
cookie 常用于识别用户。cookie 是服务器留在用户计算机中的小文件。每当相同的计算机通过浏览器请求页面时,它同时会发送 cookie。通过 PHP,您能够创建并取回 cookie 的值。

如何创建 cookie?
setcookie() 函数用于设置 cookie。

注释:setcookie() 函数必须位于 <html> 标签之前。

语法
setcookie(name, value, expire, path, domain);
例子
在下面的例子中,我们将创建名为 "user" 的 cookie,把为它赋值 "Alex Porter"。我们也规定了此 cookie 在一小时后过期:

<?php
setcookie("user", "Alex Porter", time()+3600);
?>

<html>
<body>

返回列表