PHP cookei code to record user history browsing information

Source: Internet
Author: User
Tags setcookie
Infrastructure

Common methods of Cookies:

$_cookie[' Recordluhuidudu '] get cookies
Setcookie (' Recordluhuidudu ', ", Time () -3600*24*30); Setcookie (field name, data, expiration time); Set cookies

Note

It is also the same way to reset a cookie to invalidate a previous cookie and to delete a cookie:
Setcookie (' Recordluhuidudu ', ", Time () -3600*24*30);

"Code Sample"

/** * Store the supplies ID in a cookie * * @param $id * @return BOOL */Public Function Setcookierecord ($id) {$data = null; if (!isset ($_cookie[' Recordluhuidudu ')) {if (!empty ($id)) {$data [0] = array (' id ' = $id, '      Time ' = Date (' y-m-d h:i:s ', Time ()));      }else{return false;        }}else{if (!empty ($id)) {$data = $_cookie[' Recordluhuidudu '];        Setcookie (' Recordluhuidudu ', ', Time () -3600*24*30);        $data = Json_decode ($data, true);        $num = count ($data);        Determine if repeat $judge = false; foreach ($data as $index = + $value) {if ($data [$index] [' id '] = = $id) {$data [$index] [' time '] = date (' Y            -m-d h:i:s ', Time ());          $judge = true;          }} if ($judge) {Setcookie (' Recordluhuidudu ', Json_encode ($data), Time () +3600*24*30);        return true; if ($num = =) {for ($i = 0; $i < 9; $i + +) {$data [$i] = $data [$i +1];} $data [9] = arrAY (' id ' = $id, ' time ' = ' date ' (' y-m-d h:i:s ', Time ()));          if ($num <10) {$data [$num] = array (' id ' = = $id, ' time ' = = Date (' y-m-d h:i:s ', Time ())        );        }else {return false;    }}} setcookie (' Recordluhuidudu ', Json_encode ($data), Time () +3600*24*30);  return true; }

This article originates from IT985 Blog

The above describes the PHP cookei record user History browsing information code, including the aspects of the content, I hope that the PHP tutorial interested in a friend helpful.

  • 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.