简体   繁体   English

我如何跟踪使用PHP中的Cookie访问的最近5页

[英]how can i track last 5 pages visited using cookies in php

  <?php

   session_start();
   if(empty($_SESSION['track']))
       $_SESSION['history'] = array($_SERVER['PHP_SELF']);
   else {
       $_SESSION['track'][] = $_SERVER['PHP_SELF'];
   if(count($_SESSION['track']) > 5)
       array_shift($_SESSION['track']);
   }

   function display()
   {
       print_r(array_values($_SESSION['track']));
   }
  ?>

i was able to do it using session but i need to use only cookies and php to track the last 5 pages visited. 我能够使用会话做到这一点,但是我只需要使用cookie和php来跟踪访问的最后5页。 any idea guys?? 任何想法的家伙?

Any comment or answer will appreciate. 任何意见或答案将不胜感激。 Thanking in advance. 在此先感谢。

$url = unserialize($_COOKIE['history']);
array_push($url,your_url);
setcookie('history', serialize($url));

onload of every page first retrieve the value of cookie in url and push the current url in it and add set it to cookie 每个页面的onload首先获取url中cookie的值,并将当前url推送到其中,并将其设置为cookie

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM