The example in this article describes how PHP saves the URL of the browsing history page to a cookie. Share it with everyone for your reference. The details are as follows:
Save the browsing history page URL to a cookie. The general idea is as follows, which is slightly different from the actual application.
//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);//Convert the 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){//Only save 10 access records
array_shift($arr);
}
$urls = serialize($arr);//Stored as string,
setcookie('his',$urls);//Save to cookie
}else{
$url = $_SEVER['REQUEST_URI'];//Get the current page URL
$arr[] = $url;//Save the current URL into the array
$urls = serialize($arr);//Stored as string
setcookie('his',$urls);//Save to cookie
}
echo "Previous page
";//Previous page, used for access testing
echo "Next page";//Next page, access test
?>
I hope this article will be helpful to everyone’s PHP programming design.