Home  >  Article  >  Backend Development  >  How to set cookies in php

How to set cookies in php

王林
王林Original
2020-07-21 15:38:174747browse

The method for setting cookies in php is: you can use the setcookie() function to set it, and the function must be located before the tag. The specific setting method is: [setcookie('mycookie','value');].

How to set cookies in php

#Cookies are often used to identify users. A cookie is a small file that a server leaves on a user's computer. Each time the same computer requests a page through the browser, the cookie will be sent to the computer.

(Recommended tutorial: php tutorial)

The setcookie() function is used to set cookies. This function must be located before the 100db36a723c770d327fc0aef2ce13b1 tag.

Grammar:

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

Code implementation:

setcookie('mycookie','value');
echo($mycookie);
echo($HTTP_COOKIE_VARS['mycookie']);
echo($_COOKIE['mycookie']);

The above is the detailed content of How to set cookies in php. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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