Emlog非插件实现获取评论用户操作系统与浏览器信息
首先打开 include/model/comment_model.php
文件
找到 while ($row = $this->db->fetch_array($ret)) {
(即第45行)在这里增加一个获取useragent的信息,代码:
$row['useragent'] = htmlspecialchars($row['useragent']);
如图:
其次在249行的评论提交中增加一个useragent的信息到数据库里,修改代码如下:
如图:
- function addComment($name, $content, $mail, $url, $imgcode, $blogId, $pid)
- {
- $ipaddr = getIp();
- $useragent = $_SERVER['HTTP_USER_AGENT'];
- $utctimestamp = time();
- if($pid != 0) {
- $comment = $this->getOneComment($pid);
- $content = '@' . addslashes($comment['poster']) . ':' . $content;
- }
- $ischkcomment = Option::get('ischkcomment');
- $hide = ROLE == ROLE_VISITOR ? $ischkcomment : 'n';
- $sql = 'INSERT INTO '.DB_PREFIX."comment (date,poster,gid,comment,mail,url,hide,ip,pid,useragent)
- VALUES ('$utctimestamp','$name','$blogId','$content','$mail','$url','$hide','$ipaddr','$pid','$useragent')";
- $ret = $this->db->query($sql);
- $cid = $this->db->insert_id();
- $CACHE = Cache::getInstance();
- if ($hide == 'n') {
- $this->db->query('UPDATE '.DB_PREFIX."blog SET comnum = comnum + 1 WHERE gid='$blogId'");
- $CACHE->updateCache(array('sta', 'comment'));
- doAction('comment_saved', $cid);
- emDirect(Url::log($blogId).'#'.$cid);
- } else {
- $CACHE->updateCache('sta');
- doAction('comment_saved', $cid);
- emMsg('评论发表成功,请等待管理员审核', Url::log($blogId));
- }
- }
然后打开博客模板目录,找到 module.php
文件,添加代码:
如图:
- <?php
- //获取评论用户操作系统、浏览器等信息
- function useragent($info){
- require_once 'useragent.class.php';
- $useragent = UserAgentFactory::analyze($info);
- ?>
- <img src="<?php echo TEMPLATE_URL.$useragent->platform['image']?>"> <?php echo $useragent->platform['title']; ?>
- <img src="<?php echo TEMPLATE_URL.$useragent->browser['image']?>"> <?php echo $useragent->browser['title']; ?>
- <?php
- }
- ?>
调用格式: <?php echo useragent($comment['useragent']); ?>
将这段代码添加到到 module.php
评论列表和子评论列表适当位置即可...
其他一些文件直接下载后放到模板根目录,下载地址: 密码:2qjs
凌寒 》原创,转载请保留文章出处。
本文链接:Emlog非插件实现获取评论用户操作系统与浏览器信息 http://www.wanghanyue.com/post-73.html
本作品采用 知识共享署名 4.0 国际许可协议 进行许可。
版权声明:若无特殊注明,本文皆为《
正文到此结束
发表吐槽
你肿么看?
既然没有吐槽,那就赶紧抢沙发吧!