Cookkie's Setcookie "one"

Source: Internet
Author: User

Definition and usage

The Setcookie () function sends an HTTP cookie to the client.

A cookie is a variable that is sent to the browser by the server. A cookie is usually a small text file that the server embeds into a user's computer. This cookie is sent whenever the computer requests a page through a browser.

The name of the cookie is specified as a variable of the same name. For example, if the cookie being sent is named "name", a variable named $user is automatically created, containing the value of the cookie.

The cookie must be assigned before any other output is sent.

If successful, the function returns True, otherwise false is returned.

First: Name, required parameter, this is the variable name of the cookie, you can invoke the variable named user cookie by $_cookie[' user '.

Second: value, optional parameters, the values of this COOKIE variable, such as Setcookie ("User", "PHP"), we can get PHP value by calling $_cookie[' user ');

The third: expire, optional parameter, which is used to set the time to save the cookie variable, note that we set the Unix timestamp minus the current Unix timestamp is the time the cookie variable is saved. (Unix timestamp: The number of seconds since January 1, 1970 (Midnight of Utc/gmt), in general we can get the current Unix timestamp through Time (), plus the time we want to save (in seconds), for example, Setcookie ("User", " PHP ", Time () +3600) so that we can save the user this cookie variable for 3,600 seconds. In addition, we can delete cookie variables by setting a timestamp less than the current timestamp, such as Setcookie ("User", "PHP", Time ()-1) So we delete the user's cookie variable.

Fourth: The valid range of Path,cookie, this parameter is the valid range on the next parameter domain, if path is set to "/", it is valid throughout domain, such as Setcookie ("User", "PHP", Time () + 3600, "/") so that any directory under our domain, any file can be called by $_cookie[' user ' to the value of this COOKIE variable. If path is set to "/test", then only the/test directory and subdirectories under domain are valid, such as two directories under domain: TEST1,TEST2, we are set to Setcookie ("user", "php,time () +3600, "/test1″), then only the Test1 directory can be called by $_cookie[' user '] the value of the COOKIE variable, test2 directory is not available.

Fifth: Domain,cookie A valid domain name, if domain is set to googlephp.cn, then all subdomains under googlephp.cn are valid. Suppose googlephp.cn has two subdomains, php.googlephp.cn,css.googlephp.cn, we set it to Setcookie ("User", "PHP", Time () +3600, "/", " Php.googlephp.cn "), the value of the user's cookie variable can only be obtained under the php.googlephp.cn sub-domain. Give another example: Setcookie ("User", "PHP", Time () +3600, "/test", "php.googlephp.cn"), Then the value of the user's cookie variable can only be obtained under the test directory under this subdomain of php.googlephp.cn.

Sixth: Secure, whether the value cookie is only over secure HTTPS, a value of 0 or 1, and if the value is 1, the cookie is valid only on HTTPS connections, and the default value is 0, which means that Cookei is valid on both HTTP and HTTPS connections.

Cookkie's Setcookie "one"

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.