Cookie summary in PHP5 (1)

Source: Internet
Author: User
Tags set cookie
Cookie summary in PHP5 (1) I. cookie configuration and application settings cookieboolsetcookie (stringname [, stringvalue [, intexpire [, stringpath [, stringdomain [, boolsecure]);? Delete the Cookie summary in cookieboolsetcooki PHP5 (1)

1. cookie configuration and application


Set cookie

BoolSetcookie(String name [, string value [, int expire [, string path [, string domain [, bool secure]);

?

Delete cookie

Bool setcookie (name ,"");

?

Parameter description example
Name Cookie name. Use$ _ COOKIE ['cookiename']Call the cookie named cookiename.
Value Cookie value. This value is stored on the client and cannot be used to save sensitive data. Assume thatNameIs 'cookiename', you can use$ _ COOKIE ['cookiename']Obtain the value.
Expire The time when the Cookie expires. This is a Unix timestamp, that is, the number of seconds from the Unix epoch. In other words, it is usually usedTime ()The function plus the number of seconds to set the cookie expiration time. Or useMktime (). Time () + 60*60*24*30The cookie is set to expire after 30 days. If not set, the cookie will expire after the session ends (usually closed by the browser.
Path Valid Cookie path on the server. If this parameter is set'/'Then, the cookie isDomainIs valid. if it is set'/Foo /'The cookie isDomainUnder/Foo/Directory and its subdirectories are valid, such/Foo/bar/. The default value is the current directory of the cookie.
Domain The valid domain name of the cookie. This parameter should be set'.Example.com'. Although.Not required, but it will be compatible with more browsers. If this parameter is setWww.example.comInWwwValid in the subdomain. For details, see tail matching in the Cookie specification.
Secure Indicates whether the cookie is transmitted only through a secure HTTPS connection. When setTRUEThe cookie is only set in secure connections. The default value isFALSE. 0Or1

?

Like other headers, cookies must be sent before any other output of the script (this is a protocol restriction ). This requires that the call of this function be placed before any output, includingAndLabel and any space. IfSetcookie ()If there is any output before, this function will fail and returnFALSE. IfSetcookie ()If the function runs successfullyTRUE. This does not indicate whether the user has accepted the cookie.

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.