Unserialize Error-solving ideas when using cookies to show browsing history

Source: Internet
Author: User
Tags php foreach setcookie
Unserialize error when displaying browsing history with a cookie
PHP Code
  
   
  
   '; Echo '
Next page '; if (Isset ($_cookie[' his ")) { //echo $_cookie[' his '];exit; $data = unserialize ($_cookie[' his '); $url = $_server[' Request_uri '); $data [] = $url; $data = Array_unique ($data); if (count ($data) >10) { array_shift ($data); } $urls = serialize ($data); Setcookie (' His ', $urls, Time () *2*24*3600);} else { $url = $_server[' Request_uri '); $data [] = $url; $urls = serialize ($data); Setcookie (' His ', $urls, Time () *2*24*3600);}? >

  • Browse History
  • ">

After opening in the browser and entering an ID on the address bar, the browser gives a hint
HTML Code
  
   Notice:unserialize () [function.unserialize]: Error at offset 9 of the bytes in D:\server\apache\www\20120413\history.php o N Line 16

And show the history of one, I think it may be related to the above error, can not find a solution, grammar I saw a few pieces, temporarily did not find the above error, looking for the!!!!!!

------Solution--------------------
$data = Unserialize (stripslashes ($_cookie[' his '));

So try, not to print out the cookie value to be affixed,
  • Related Article

    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.