15621857753

PHPCMSV9版如何实现浏览记录功能

来源:齐鲁建站 栏目:开发教程 阅读: 日期:2020-08-08

最近使用PHPCMS建站,有个客户想要实现PHPCMSV9版如何实现浏览记录功能,这在建站视频类网站方面特别有用。齐鲁建站小编经过查找相关资料解决了这个问题,下面就来说说phpcms浏览记录的方法。

下面就来说说phpcms浏览记录的方法。

PS:适用版本号:9.3.3

在参考了PC文章的浏览记录后,解决如下:

1、不需要改动原来文件。新增一个文件及一个模板文件。

2、静态页面AJAX调用。

步骤:

1、根目录下新增文件readid.php。

header("Cache-Control: no-cache, must-revalidate");
include 'phpcms'.DIRECTORY_SEPARATOR.'base.php'; 
pc_base::load_sys_class('param', '', 0);
$contentid = isset($_GET['contentid']) ? intval($_GET['contentid']) : 0;
$readid = param::get_cookie('readid');
$action = $_GET['action'];
if(intval($readid))$readwhere = $readid;
switch($action) 
case 'read':
  if($contentid){
   if(intval($readid))
    {
     $readid = $contentid.','.$readid;
     $tmp = explode(",",$readid);
     $tmp = array_unique($tmp);
     while(count($tmp) > 10)array_pop($tmp);
     $readid = implode(",",$tmp);
    }
    else $readid = $contentid;
    param::set_cookie('readid',$readid,time()+3600*365*24);
  }
break;
 
case 'list':
  include template('content', 'read_fang');
break;
}
?>

2、新增模板文件read_fang.html

    {if $readwhere}
    {pc:get sql="SELECT * FROM `news` WHERE id IN ($readwhere) AND status = '99' ORDER BY FIND_IN_SET(id,'$readwhere')" rows="10"}
    {loop $data $key $r}
    {/loop}
    {/pc}
    {else}
    • 您还没有浏览过信息
    {/if}
     

    3、静态页面调用:

    (1)、需要调用的内容页面模板文件,如show.html,加上:

    <script language="JavaScript" src="readid.php?contentid={$contentid}&action=read"></script>

    (2)、浏览页调用:

    先添加JS代码:

    <script type="text/javascript">
    $(document).ready(function(){ 
    $('#readhouse').load("readid.php?action=list");
    }); 
    </script>

    在需要浏览记录显示的地方,添加:

     

    数据加载中

     

    以上就是关于phpcms浏览记录的所有内容,有需要的朋友试试看吧。

    展开