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
版权声明:若无特殊注明,本文为《明月浩空》原创,转载请保留文章出处。
本文链接:https://blog.myhkw.cn/emlog_useragent.html
正文到此结束







匿名
a'ゞ 打驴
九哥
a'ゞ 打驴
a'ゞ 打驴
只为一人て
OldDriver
风宁
我
谕世
Z.Howe
印象素