用cookie显示浏览历史时, unserialize出错
<!--
Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/
-->
<?php
$id = $_GET['id']+0;
echo '<a href="history.php?id=' . ($id-1) . '">上一页</a><br/>';
echo '<br/><a href="history.php?id=' . ($id+1) . '">下一页</a>';
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);
}
?>
<br /><br />
<ul>
<li>浏览历史</li>
<?php foreach($data as $v) { ?>
<li><a href="<?php echo $v; ?>"><?php echo $v; ?></a></li>
<?php } ?>
</ul>
<!-- Code highlighting produced by Actipro CodeHighlighter (freeware) http://www.CodeHighlighter.com/ --> Notice: unserialize() [function.unserialize]: Error at offset 9 of 41 bytes in D:\server\apache\www\20120413\history.php on line 16
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号