16/7/8_php-Setting cookies

Source: Internet
Author: User

The most common way to set up cookies in PHP is to use the Setcookie function, Setcookie has 7 optional parameters, which we commonly used for the first 5:

Name (COOKIE name) can be accessed by $_cookie[' name ')
Value (values of the cookie)
Expire (expiry time) UNIX timestamp format, default = 0, indicates that the browser is off and is invalidated
Path (valid path) if the path is set to '/', the entire site is valid
Domain (valid domain) default entire domain name is valid, if ' www.imooc.com ' is set, it is only valid in WWW subdomain

$value = ' test '; Setcookie ("TestCookie", $value), Setcookie ("TestCookie", $value, Time () +3600);  Valid for one hour Setcookie ("TestCookie", $value, Time () +3600, "/path/", "imooc.com"); Set path and domain

PHP also has a function to set the cookie Setrawcookie,setrawcookie is basically the same as Setcookie, the only difference is that value values are not automatically urlencode, It is therefore necessary to manually carry out the urlencode when needed.


 

Because cookies are set by HTTP headers, they can also be set directly using the header method.

Header ("Set-cookie:cookie_name=value");

16/7/8_php-Setting cookies

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.