How to set cookies in php

王林
Release: 2023-03-02 19:38:02
Original
4753 people have browsed it

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 tag.

Grammar:

setcookie(name, value, expire, path, domain);
Copy after login

Code implementation:

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

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!

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