TDLIB > PHP
PHP Cookie使用
Allen   ·  2020.0922 13:00:13
Stat:1088v. 0r. 0u. 0d. 0f 
#0. (Normal)

PHP Cookie使用

+++创建 Cookie

--创建user的cookie,并为它赋值Alex Porter,在一小时后过期

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

--另一种方式设置 cookie 的过期时间

$expire=time()+60*60*24*30;

setcookie("user", "Alex Porter", $expire);

+++取回 Cookie 的值

echo $_COOKIE["user"];

--我们使用 isset() 函数来确认是否已设置了 cookie:

<?php

 if (isset($_COOKIE["user"]))

 echo "Welcome " . $_COOKIE["user"] . "!<br>";

 else

 echo "Welcome guest!<br>";

 ?>

+++删除 Cookie

 setcookie("user", "", time()-3600);

【Copyright Notice】
This article is original, follow CC 4.0 BY-SA copyright agreement! Please indicate the original url when repost.
Original url:https://tdlib.com/am.php?t=WuyIVgQJMFE8

No Tags
Next
【Related content】
Top     1/1 
You are not logged in, please [Register] or [Login]
(Register in one minute!)
Copyright ©TDLIB, All Rights Reserved.
Powered by TYCMS Version 1002