PHP cookies deletion, value assignment method _ PHP Tutorial

Source: Internet
Author: User
Tags set cookie
Delete phpcookies and assign values. Delete cookies in the php Tutorial. The value assignment method cookie is often used to identify users. Cookie is a small file that the server stays on the user's computer. Every time the same computer requests a page through a browser, the php Tutorial deletes cookies and assigns values.

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. With php, you can create and retrieve cookie values

Syntax

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

**
* Set cookie
* N name
* C value
* E validity period 0: one month by default; 1: disabled; expired immediately
*/

Function w_cookie ($ n, $ c, $ e = 0, $ isdes = 1)
{
If ($ isdes = 1) {$ c = endes ($ c, Region EY );}
$ Exp = time () + 3600*24*30;
If ($ e = 0)
{
Setcookie ($ n, $ c, $ exp ,"/");
}
Else
{
Setcookie ($ n, $ c, 0 ,"/");
}
}



// Method for disabling cookies

W_cookie ('BB ', 'www. bKjia. c0m', $ e = 0, $ isdes = 1 );


For more details, see http://www.bKjia. c0m/phper/php/34040.htm

More detailed method

Function set_cronology ($ name, $ value, $ duration = 7 ){
$ Duration = time () + (3600*24 * $ duration );
$ Max_stored_values = 5;
If (isset ($ _ cookie [$ name]) {
Foreach ($ _ cookie [$ name] as $ prop_crono => $ val_crono ){
If ($ val_crono = $ value)
Return;
}
If ($ prop_crono <$ max_stored_values)
Setcookie ($ name. '['. ($ prop_crono + 1). ']', $ value, $ duration );
Else {
Array_shift ($ _ cookie [$ name]);
Setcookie ("$ name [$ max_stored_values]", $ value, $ duration );
}
} Else
Setcookie ($ name. '[0]', $ value, $ duration );
Return;
}
?>

Note: The setcookie () function must be locatedBefore the tag. When sending a cookie, the cookie value is automatically url encoded and automatically decoded when Retrieved. to prevent url encoding, use setrawcookie () instead ).

Cookies are deleted. value assignment: 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...

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.