PHP implements the method of saving browsing history page URLs to cookies, Phpcookie
This article explains how PHP implements a way to save a browsing history page URL to a cookie. Share to everyone for your reference. Specific as follows:
Save the Browsing history page URL to a cookie, with a general idea like the following code, which is somewhat different from the actual application.
Copy the Code code as follows: <?php
/*******
Note: The cookie can only save the string in this instance, need to save multiple URLs (historical access Records), the idea is to first convert the URL array into a string, and then save, read, and then loop read
*******/
First assume that the current URL is: http://localhost/php/?id=1
$id = $_get[' id '];
if (Isset ($_cookie[' his ')) {
$urls = $_cookie[' His '];//read COOKIE
$arr = Unserialize ($urls);//String back to the original array
$arr [] = $_server[' Request_uri '];//the current page URL is added to the array
$arr = Array_unique ($arr);//Remove Duplicate
if (count ($arr) >10) {//Save only 10 Access records
Array_shift ($arr);
}
$urls = serialize ($arr);//stored as a string,
Setcookie (' his ', $urls);//Save to Cookie
}else{
$url = $_sever[' Request_uri '];//gets the current page URL
$arr [] = $url;//Save the current URL to an array
$urls = serialize ($arr);//stored As String
Setcookie (' his ', $urls);//Save to Cookie
}
echo "Previous page
";//previous page, Access test
echo "Next page";//Next page, Access test
?>
History visit page
<?php foreach ($arr as $v) {?>
- "><?php Echo $v;?>
<?php}?>
I hope this article is helpful to everyone's PHP programming.
http://www.bkjia.com/PHPjc/947928.html www.bkjia.com true http://www.bkjia.com/PHPjc/947928.html techarticle PHP Implementation of the browsing history page URLs saved to the cookie method, Phpcookie This article describes the PHP implementation of the browsing history page URLs saved to the cookie method. Share for everyone to join us ...