In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
Today, I will talk to you about how php uses setcookie () to set cookie to never expire. Many people may not know much about it. In order to make you understand better, the editor has summarized the following content for you. I hope you can get something according to this article.
In php, you only need to set the value of the third parameter of the setcookie () function that is always greater than the current time of the system. The syntax "setcookie (" cookie_name "," cookie_value ", time () + 99, 365, 24, 3600).
Operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer
When you set cookie in PHP, if you do not specify a validity period, the life cycle will be a period of time for the browser, which can also be called no save, and it will be gone when the browser is closed and opened again.
If you set a longer validity period for cookie (which is always greater than the current system time), you can make cookie never expire. The third parameter of the setcookie () function, $expire, is used to set the cookie validity period. For example, the following code:
Setcookie ("cookie_name", "cookie_value", time () + 99 * 36524 * 3600)
Description:
The syntax format of the setcookie () function is as follows:
Setcookie (string $name [, string $value = "" [, int $expire = 0 [, string $path = "" [, string $domain = "" [, bool $secure = false [, bool $httponly = false])
The parameters are described as follows:
$name: sets the name of the Cookie
Value: optional parameter, which is used to set the value of Cookie. You can get the value of $value in the form of $_ COOKIE ['$name']
Expire: optional parameter, which is used to set the expiration time of Cookie, which is in the form of Unix timestamp. If set to zero or omitted, Cookie expires at the end of the session (that is, when the browser is closed)
$path: optional parameter, which is used to set the Cookie valid server path. When set to'/', Cookie is valid for the entire domain name $domain. If set to'/ foo/', Cookie is only valid for the / foo/ directory and its subdirectories in $domain (for example, / foo/bar/). The default value is the directory when setting Cookie
$domain: optional parameter, which is used to set the valid domain name / subdomain name of Cookie. Setting it as a subdomain name (for example, 'c.biancheng.net') makes Cookie valid for this subdomain name and its third-level domain name (for example, php.c.biancheng.net). To make Cookie valid for the entire domain name (including all its subdomains), simply set it to a domain name (for example, 'biancheng.net')
Secure: an optional parameter that sets whether the Cookie is passed to the client only over a secure HTTPS connection. When set to TRUE, Cookie is set only if a secure connection exists
$httponly: optional. When set to TRUE, Cookie can only be accessed through the HTTP protocol, which means that Cookie cannot be accessed through a scripting language like JavaScript. Setting this parameter can effectively reduce the risk of XSS attacks.
Time () returns the number of seconds in the current time since the Unix era (January 1 1970 00:00:00 GMT).
After reading the above, do you have any further understanding of how php uses setcookie () to set cookie to never expire? If you want to know more knowledge or related content, please follow the industry information channel, thank you for your support.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.