PHP Cookies
如何创建 Cookie?
setcookie() 函数用于设置 cookie。 注释:setcookie() 函数必须位于 标签之前。 语法: setcookie(name, value, expire, path, domain); 在下面的例子中,我们将创建名为 "user" 的 cookie,并为它赋值 "Alex Porter"。我们也规定了此 cookie 在一小时后过期:
- setcookie("user","AlexPorter",time()+3600);
- ?>
- .....
注释:在发送 cookie 时,cookie 的值会自动进行 URL 编码,在取回时进行自动解码。(为防止 URL 编码,请使用 setrawcookie() 取而代之。)
如何取回 Cookie 的值?
PHP 的 $_COOKIE 变量用于取回 cookie 的值。 在下面的实例中,我们取回了名为 "user" 的 cookie 的值,并把它显示在了页面上:在下面的实例中,我们使用 isset() 函数来确认是否已设置了 cookie:
- //Printacookie
- echo$_COOKIE["user"];
- //Awaytoviewallcookies
- print_r($_COOKIE);
- ?>
- if(isset($_COOKIE["user"]))
- echo"Welcome".$_COOKIE["user"]."!
";- else
- echo"Welcomeguest!
";- ?>
如何删除 Cookie?
当删除 cookie 时,您应当使过期日期变更为过去的时间点。
删除的实例:
- //settheexpirationdatetoonehourago
- setcookie("user","",time()-3600);
- ?>
JavaScript 如何创建、获取Cookies

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

Zend Studio 13.0.1
Powerful PHP integrated development environment

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

Notepad++7.3.1
Easy-to-use and free code editor
