Home > Backend Development > PHP Tutorial > Implementation of cookies in php

Implementation of cookies in php

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-08-08 09:19:44
Original
1185 people have browsed it

Cookie implementation

Cookies are different from sessions. As long as the session is passed to the server, it can be used on this web page. However, if the cookie is not set with attributes, it can only be used under the current path.

Cookie has 5 attributes that are used when using setcookie ("name", value, time, path, domain).

You need to operate the path when you want to use it on other pages. If you use "/" instead of path, it can be used on the entire web page.

When defining time, you need to operate time(), such as

setcookie("name", value, time() + 3600);

This is to save the cookie for 1 hour. The webpage will automatically log out the cookie after one hour;

Use $_COOKIE("name"); to retrieve the cookie value when retrieving cookie data.

Cookie deletion

There are two ways to delete cookies, one is setcookie("name"); the other is to reset the time to 0; setcookie("name", value, 0); that's it

Copyright Statement: This article is an original article by the blogger and may not be reproduced without the blogger's permission.

The above introduces the implementation of cookies in PHP, including aspects of it. I hope it will be helpful to friends who are interested in PHP tutorials.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template