COOKIE support explanation for PHP4 is transferred from Aesop

Source: Internet
Author: User
Tags set cookie
Cookies of PHP4 support the establishment of commercial sites or well-functional personal sites. visitors often need to be recorded. in PHP, two convenient methods are provided: session and COOKIE functions. cookie is the most convenient method to keep user information permanently. here I will explain cooSyntaxHighlighte in detail

Cookies of PHP4 support the establishment of commercial sites or well-functional personal sites. visitors often need to be recorded. in PHP, two convenient methods are provided: session and COOKIE functions. cookie is the most convenient method to keep user information permanently. here I will explain in detail the functions and usage of cookies. 1. set cookie before using cookie. function prototype: int setcookie (string name, string value, int expire, string path, string domain, int secure). all parameters except name are optional, you can use an empty string to indicate that it is not set. attribute value: Used to specify the value. attribute path: specifies the directory path in which the cookie is sent to the server. attribute domain: limits the sending of cookies on the browser side. expire parameter: Used to specify the cookie validity period, which is a standard Unix time mark. it can be obtained using the time () or mktime () function, in seconds. secure parameter: indicates whether the cookie is transmitted over the network through the encrypted HTTPS protocol. II. notes for setting cookies: setting cookies on the same page is actually performed in the order from the back to the back. if you want to delete a cookie and then write a cookie, you must first write the statement and then write the delete statement. otherwise, an error occurs. 3. setcookie example: setcookie ("mycookie", "value_of_mycookie"); setcookie with Expiration time ("withExpire", "expire_in_{hour", time () + 3600 ); everything: setcookie ("FullCookie", "Full_cookie_value", time + 3600, "/forum", "www.123.com", 1); 4: cookies are path-oriented. by default, the WEB server page will automatically pass the current path to the browser. the specified path will force the server to use the set path. the cookie set in one directory page is invisible on the page of another directory. v. receiving and processing cookies PHP automatically processes cookies, just like the principles for processing FORM variables. of course, you can also use the PHP global variable, $ HTTP_COOKIE_VARS array. example: echo $ mycookie; echo $ cookie Array [0]; echo count ($ cookie Array); echo $ HTTP_COOKIE_VARS ["mycookie"]; 6: delete cookie (1) call the setcookie () with only the name parameter; (2) set the expiration time to time () or time-1; 7: Use the cookie limit (1) it must be set before the HTML file content is output; (2) different browsers may not process cookies; (3) client restrictions, for example, if a user sets cookie prohibition, the cookie cannot be established. 8: A specific example is provided. I hope you will have a better understanding of the cookie. Through the above introduction, do you have a detailed understanding of the COOKIE function in PHP. use your intelligence to make your site more powerful. if you have any questions, please contact fbigov@sina.com. let's make progress together.

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.