帝国cms常见问题:实现用户当前访问的历史记录(产品浏览记录)

帝国如何实现调用用户的访问记录,今天跟着小编来看一看吧,效果图如下一:在e/class/userfun.php中加://--------------------开始------------------
function user_SetCook($nam

帝国如何实现调用用户的访问记录,今天跟着小编来看一看吧,效果图如下SsqECMSPLUS

帝国CMS(EmpireCMS)实现用户当前访问的历史记录(产品浏览记录)SsqECMSPLUS

一:在e/class/userfun.php中加:SsqECMSPLUS

//--------------------开始------------------SsqECMSPLUS
function user_SetCook($name, $id, $time = 0, $num = 10) { //cookie名称 ID 时间戳 数量SsqECMSPLUS
    if (!$id) {SsqECMSPLUS
        printerror2('不存在的记录', $_SERVER['HTTP_REFERER']);SsqECMSPLUS
    }SsqECMSPLUS
    $prodq = $id . '|';SsqECMSPLUS
    $projilu = getcvar($name);SsqECMSPLUS
    if ($projilu) {SsqECMSPLUS
        $prozuhe = $prodq . $projilu; //把新浏览的放在第一SsqECMSPLUS
        $pro_arr = explode('|', $prozuhe);SsqECMSPLUS
        $new_arr = array_merge(array_unique($pro_arr)); //去除重复,重新索引下标SsqECMSPLUS
        foreach ($new_arr as $key => $val) {SsqECMSPLUS
            if (($key < $num) && $val) {SsqECMSPLUS
                $pro.= $val . '|';SsqECMSPLUS
            }SsqECMSPLUS
        }SsqECMSPLUS
    } else {SsqECMSPLUS
        $pro = $prodq;SsqECMSPLUS
    }SsqECMSPLUS
    esetcookie($name, $pro, $time);SsqECMSPLUS
    //esetcookie($name,'',0);SsqECMSPLUS
    //print_r($_COOKIE);SsqECMSPLUS
    SsqECMSPLUS
}SsqECMSPLUS
function user_GetCook($name, $tbname, $num = 10) { //名称 数据表 数量SsqECMSPLUS
    global $empire, $dbtbpre;SsqECMSPLUS
    if (preg_match("/^[0-9|]+$/", getcvar($name))) {SsqECMSPLUS
        $jilu_all = substr(getcvar($name), 0, -1); //1|2|3SsqECMSPLUS
        $jilu_arr = explode('|', $jilu_all);SsqECMSPLUS
        foreach ($jilu_arr as $k => $v) {SsqECMSPLUS
            $jilu_idin.= (int)$v . ',';SsqECMSPLUS
        }SsqECMSPLUS
        $jilu_idin = substr($jilu_idin, 0, -1); //1,2,3SsqECMSPLUS
        $sql = $empire->query("select id,title,titlepic,titleurl from {$dbtbpre}ecms_{$tbname} where id in ({$jilu_idin}) order by find_in_set(id,'{$jilu_idin}') limit {$num}"); //按id in 里面的排序SsqECMSPLUS
        while ($jilu_r = $empire->fetch($sql)) {SsqECMSPLUS
            $titleurl = sys_ReturnBqTitleLink($jilu_r);SsqECMSPLUS
            echo '<li><a href="' . $titleurl . '">' . $jilu_r['title'] . '</a></li>'; //此处是修改样式需要图片自己加SsqECMSPLUS
            SsqECMSPLUS
        }SsqECMSPLUS
    } else {SsqECMSPLUS
        echo '暂时浏览记录!';SsqECMSPLUS
    }SsqECMSPLUS
}SsqECMSPLUS
//--------------------结束------------------SsqECMSPLUS

二:在内容页模版最上面加:SsqECMSPLUS

<?=user_SetCook('cookiepro',$navinfor[id],0,10);//cookie名称可以自己定别重复 ID 时间戳 数量 ?>SsqECMSPLUS

三:在要显示的地方加一句:SsqECMSPLUS

<?=user_GetCook('cookiepro','shop',10);//名称 数据表名 数量 ?>SsqECMSPLUS

如下示例代码:

<p>//--------------------开始------------------<br />function user_SetCook($name, $id, $time = 0, $num = 10) { //cookie名称 ID 时间戳 数量<br />&nbsp; &nbsp; if (!$id) {<br />&nbsp; &nbsp; &nbsp; &nbsp; printerror2(&#39;不存在的记录&#39;, $_SERVER[&#39;HTTP_REFERER&#39;]);<br />&nbsp; &nbsp; }<br />&nbsp; &nbsp; $prodq = $id . &#39;|&#39;;<br />&nbsp; &nbsp; $projilu = getcvar($name);<br />&nbsp; &nbsp; if ($projilu) {<br />&nbsp; &nbsp; &nbsp; &nbsp; $prozuhe = $prodq . $projilu; //把新浏览的放在第一<br />&nbsp; &nbsp; &nbsp; &nbsp; $pro_arr = explode(&#39;|&#39;, $prozuhe);<br />&nbsp; &nbsp; &nbsp; &nbsp; $new_arr = array_merge(array_unique($pro_arr)); //去除重复,重新索引下标<br />&nbsp; &nbsp; &nbsp; &nbsp; foreach ($new_arr as $key =&gt; $val) {<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (($key &lt; $num) &amp;&amp; $val) {<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $pro.= $val . &#39;|&#39;;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br />&nbsp; &nbsp; &nbsp; &nbsp; }<br />&nbsp; &nbsp; } else {<br />&nbsp; &nbsp; &nbsp; &nbsp; $pro = $prodq;<br />&nbsp; &nbsp; }<br />&nbsp; &nbsp; esetcookie($name, $pro, $time);<br />&nbsp; &nbsp; //esetcookie($name,&#39;&#39;,0);<br />&nbsp; &nbsp; //print_r($_COOKIE);<br />&nbsp; &nbsp;&nbsp;<br />}<br />function user_GetCook($name, $tbname, $num = 10) { //名称 数据表 数量<br />&nbsp; &nbsp; global $empire, $dbtbpre;<br />&nbsp; &nbsp; if (preg_match(&quot;/^[0-9|]+$/&quot;, getcvar($name))) {<br />&nbsp; &nbsp; &nbsp; &nbsp; $jilu_all = substr(getcvar($name), 0, -1); //1|2|3<br />&nbsp; &nbsp; &nbsp; &nbsp; $jilu_arr = explode(&#39;|&#39;, $jilu_all);<br />&nbsp; &nbsp; &nbsp; &nbsp; foreach ($jilu_arr as $k =&gt; $v) {<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $jilu_idin.= (int)$v . &#39;,&#39;;<br />&nbsp; &nbsp; &nbsp; &nbsp; }<br />&nbsp; &nbsp; &nbsp; &nbsp; $jilu_idin = substr($jilu_idin, 0, -1); //1,2,3<br />&nbsp; &nbsp; &nbsp; &nbsp; $sql = $empire-&gt;query(&quot;select id,title,titlepic,titleurl from {$dbtbpre}ecms_{$tbname} where id in ({$jilu_idin}) order by find_in_set(id,&#39;{$jilu_idin}&#39;) limit {$num}&quot;); //按id in 里面的排序<br />&nbsp; &nbsp; &nbsp; &nbsp; while ($jilu_r = $empire-&gt;fetch($sql)) {<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $titleurl = sys_ReturnBqTitleLink($jilu_r);<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; echo &#39;&lt;li&gt;&lt;a href=&quot;&#39; . $titleurl . &#39;&quot;&gt;&#39; . $jilu_r[&#39;title&#39;] . &#39;&lt;/a&gt;&lt;/li&gt;&#39;; //此处是修改样式需要图片自己加<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<br />&nbsp; &nbsp; &nbsp; &nbsp; }<br />&nbsp; &nbsp; } else {<br />&nbsp; &nbsp; &nbsp; &nbsp; echo &#39;暂时浏览记录!&#39;;<br />&nbsp; &nbsp; }<br />}<br />//--------------------结束------------------</p>
分享到 :
相关推荐

发表评论

登录... 后才能评论

评论(3)

加入本站VIP会员订阅计划,海量资源免费下载查看

目前为止共有3位优秀的VIP会员加入!

立即加入VIP会员