php浏览历史记录的方法,php浏览历史记录
本文实例讲述了php浏览历史记录的方法。分享给大家供大家参考。具体实现方法如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
private function _history( $data )
{
if (! $data || ! is_array ( $data ))
{
return false;
}
if ( $this ->_request->getCookie( 'history' ))
{
$history = unserialize( $this ->_request->getCookie( 'history' ));
array_unshift ( $history , $data );
$rows = array ();
foreach ( $history as $v )
{
if (in_array( $v , $rows ))
{
continue ;
}
$rows [] = $v ;
}
while ( count ( $rows ) > 5)
{
array_pop ( $rows );
}
setcookie( 'history' ,serialize( $rows ),time()+3600*24*30, '/' );
}
else
{
$history = serialize( array ( $data ));
setcookie( 'history' , $history ,time()+3600*24*30, '/' );
}
}
|
Copy after login
希望本文所述对大家的php程序设计有所帮助。