thinkphp Browsing historical functions, thinkphp history _php Tutorials

Source: Internet
Author: User

thinkphp Browsing Historical Function realization method, thinkphp history


The example of this article describes the Thinkphp browsing history function Realization method, share for everyone for reference. The specific implementation method is analyzed as follows:

The history browsing function uses the cookie function to log the user's information to the local, so that we just read the value stored in the cookie can be, the following is to introduce an example based on thinkphp to implement the browsing history function.

Just like a browser, you can record which pages are accessed, which reduces the time, and below we realize the function of browsing history.

1. In the product or news page where you need to record your browsing data, record the information that the cookie needs to be saved, such as the following line of code, which passes the page ID, product name, price, thumbnail, and URL to cookie_history.

Copy the code as follows: Cookie_history ($id, $info [' title '], $info [' Price '], $info [' pic '], $thisurl);
2.function.php inside Add code

Copy CodeThe code is as follows:/**
+----------------------------------------------------------
* Browse records sorted by Time
+----------------------------------------------------------
*/
function My_sort ($a, $b) {
$a = substr ($a, 1);
$b = substr ($b, 1);
if ($a = = $b) return 0;
return ($a > $b)? -1:1;
}
/**
+----------------------------------------------------------
* Web browsing record generation
+----------------------------------------------------------
*/
function Cookie_history ($id, $title, $price, $img, $url) {
$dealinfo [' title '] = $title;
$dealinfo [' price '] = $price;
$dealinfo [' img '] = $img;
$dealinfo [' url '] = $url;
$time = ' t '. Now_time;
$cookie _history = Array ($time = Json_encode ($dealinfo)); Set cookies
if (!cookie (' history ')) {//cookie NULL, the initial one
Cookies (' History ', $cookie _history);
}else{
$new _history = array_merge (Cookie (' history '), $cookie _history);//Add New browsing data
Uksort ($new _history, "My_sort");//Sort by browse time
$history = Array_unique ($new _history);
if (count ($history) > 4) {
$history = Array_slice ($history, 0,4);
}
Cookies (' history ', $history);
}
}
/**
+----------------------------------------------------------
* Web browsing record reading
+----------------------------------------------------------
*/
function Cookie_history_read () {
$arr = Cookie (' history ');
foreach ((array) $arr as $k = + $v) {
$list [$k] = Json_decode ($v, true);
}
return $list;
}
3. The page output information that needs to display the browsing history

Copy the code as follows: $this->assign (' History ', Cookie_history_read ());
The template is displayed with Volist.

I hope this article is helpful to everyone's PHP programming.


Thinkphp to achieve the most basic functions can be

This is an action class, the last sentence $this->display (' public:text '); Is the text template displayed under public. This means that the class is executed first, and then the template is displayed. The variables used in the template are called from here to assign allocation past. For example, $this->assign (' time '), which is to assign the current period to a template with the date name. The HTML code inside the else should be written to the template.

How can this work be achieved with thinkphp?

The front desk is a multi-box, and then in the controller to determine whether the multi-box is selected, with the where grammar match selected. Generally $this->dao->where ("show only goods = $a")

http://www.bkjia.com/PHPjc/902779.html www.bkjia.com true http://www.bkjia.com/PHPjc/902779.html techarticle thinkphp Browsing History function Realization method, thinkphp history This article narrates thinkphp browsing history function Realization method, share to everybody for everybody reference. The specific implementation method is analyzed as follows: ...

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