PHP cookie details-PHP source code

Source: Internet
Author: User
Ec (2); what is cookie? Cookies are often used to identify users. Cookie is a small file that the server stays on the user's computer. When the same computer requests a page through a browser, it sends a cookie at the same time. Through the php tutorial, you can create and retrieve the cookie value. How to Create a cookie? The setcookie () function is used to set the cookie. Note: The setcookie () function must be located in & lt; html & gt; script ec (2); script

What is cookie?
Cookies are often used to identify users. Cookie is a small file that the server stays on the user's computer. When the same computer requests a page through a browser, it sends a cookie at the same time. Through the php tutorial, you can create and retrieve the cookie value.
How to Create a cookie?
The setcookie () function is used to set the cookie.

Note: The setcookie () function must be locatedBefore the tag.

Syntax
Setcookie (name, value, expire, path, domain );

Function cookie ($ var, $ value = '', $ time = 0, $ path ='', $ domain = ''){
$ _ Cookie [$ var] = $ value;
If (is_array ($ value )){
Foreach ($ value as $ k => $ v ){
Setcookie ($ var. '['. $ k. ']', $ v, $ time, $ path, $ domain, $ s );
}
} Else {
Setcookie ($ var, $ value, $ time, $ path, $ domain, $ s );
}


What if the browser does not support cookies?
If your application involves a browser that does not support cookies, you have to use other methods to pass information from one page to another in the application. One way is to pass data from the form (the content about the form and user input is described earlier in this tutorial ).

The following form submits user input to "welcome. php" when the user clicks the submit button:



Retrieve the value in "welcome. php" as follows:


Welcome .

You are Years old.


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.