Delete phpcookies and assign values

Source: Internet
Author: User
Cookies are often used to identify users. Cookies are small files that the server stays in the user's computer. when the same computer requests a page through a browser, they send a cookie at the same time.

Cookies are often used to identify users. Cookies are small files that the server stays in the user's computer. when the same computer requests a page through a browser, they send cookies at the same time, you can create and retrieve the cookie value

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

  1. **
  2. * Set cookie
  3. * N name
  4. * C value
  5. * E validity period 0: one month by default; 1: disabled; expired immediately
  6. */
  7.  
  8. Function w_cookie ($ n, $ c, $ e = 0, $ isdes = 1)
  9. {
  10. If ($ isdes = 1) {$ c = endes ($ c, Region EY );}
  11. $ Exp = time () + 3600*24*30;
  12. If ($ e = 0)
  13. {
  14. Setcookie ($ n, $ c, $ exp ,"/");
  15. }
  16. Else
  17. {
  18. Setcookie ($ n, $ c, 0 ,"/");
  19. }
  20. }

How to disable cookie:W_cookie ('BB ', 'www .phpfensi.com', $ e = 0, $ isdes = 1 );

The detailed method is as follows:

  1. Function set_cronology ($ name, $ value, $ duration = 7 ){
  2. $ Duration = time () + (3600*24 * $ duration );
  3. $ Max_stored_values = 5;
  4. If (isset ($ _ cookie [$ name]) {
  5. Foreach ($ _ cookie [$ name] as $ prop_crono => $ val_crono ){
  6. If ($ val_crono = $ value)
  7. Return;
  8. }
  9. If ($ prop_crono <$ max_stored_values)
  10. Setcookie ($ name. '['. ($ prop_crono + 1). ']', $ value, $ duration );
  11. Else {
  12. Array_shift ($ _ cookie [$ name]);
  13. Setcookie ("$ name [$ max_stored_values]", $ value, $ duration );
  14. }
  15. } Else
  16. Setcookie ($ name. '[0]', $ value, $ duration );
  17. Return;
  18. }
  19. ?>

Note:The setcookie () function must be locatedBefore the tag is sent, the cookie value is automatically url encoded and automatically decoded during retrieval (to prevent url encoding, use setrawcookie () instead ).

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.