How to set cookies in php

藏色散人
Release: 2023-03-02 22:52:01
Original
3208 people have browsed it

The syntax for setting cookies in PHP is "setcookie("user",$user,time() 3600);", where "user" represents the user name and "$user" represents the value of the variable.

How to set cookies in php

PHP Setting and Reading Cookie

1. Setting Cookie

setcookie("user",$user,time()+3600); // user 为用户名,$user 为变量的值
Copy after login

Recommended: "PHP Tutorial

Second, read Cookie

echo @$_COOKIE["user"];
Copy after login

Related introduction:

setcookie — Send Cookie

Instructions

setcookie ( string $name [, string $value = "" [, int $expire = 0 [, string $path = "" [, string $domain = "" [, bool $secure = false [, bool $httponly = false ]]]]]] ) : bool
Copy after login

setcookie() defines the cookie, which will be sent to the client together with the remaining HTTP headers. Like other HTTP headers, the cookie must be sent before the script can produce any output (due to protocol limitations). Please call this function before producing any output (includingandor spaces).

Once the cookie is set, you can use $_COOKIE to read it the next time you open the page. Cookie values also exist in $_REQUEST.

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
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!