我有以下内容将前 10 个 URL 存储到会话中:
function curPageURL() {
$pageURL = 'http';
if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";}
$pageURL .= "://";
if ($_SERVER["SERVER_PORT"] != "80") {
$pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
} else {
$pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
}
return $pageURL;
}
//Insert Current URL in SESSION
$CurrentPage = curPageURL();
if(strpos($CurrentPage, '/products/'))
{
echo "<div class=\"title\">Recently viewed products</div>
<div id=\"recent\">";
$_SESSION['pages'][] = $CurrentPage;
if ( Count ( $_SESSION['pages'] ) > 10 )
Array_Shift ( $_SESSION['pages'] );
如何确保只存储唯一的条目?
谢谢,
乙
if(!in_array($CurrentPage, $_SESSION['pages']) {
$_SESSION['pages'][] = $CurrentPage;
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)