PHP Cookie Detailed

Source: Internet
Author: User

What is a cookie?
Cookies are often used to identify users. Cookies are small files that the server leaves on the user's computer. Whenever the same computer requests a page through a browser, it sends cookies as well. Through the PHP tutorial, you can create and retrieve the value of a cookie.
How do I create cookies?
The Setcookie () function is used to set cookies.

Note: the Setcookie () function must precede the

Grammar
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 will have to take other steps to pass information from one page to another in your application. One way is to pass data from a form (for forms and user input, as we've already covered in this tutorial earlier).

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

<body>

<form action= "welcome.php" method= "POST"
Name: <in Put type= ' text ' name= ' name '/>
Age: <input type= ' text ' name= ' age '/>
<input type= ' submit '/>
&L T;/form>

</body>

<body>

Welcome <?php echo $_post["name";? >.<br/>
You are <?php echo $_post[' age ';?> years ol D.

</body>

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.