以前通常都是使用得插件实现,那现在可以不用插件即可实现如果你是喜欢折腾您的博客的可以来尝试改动一下下面是具体的步骤首先找到并打开 include/model/comment_model.php 文件 找到如下代码(一般在第45行)while ($row = $this->db->fetch_array($ret)){
//在这里增加一个获取useragent的信息
}在上面的位置增加一个获取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));
}
}
然后打开Emlog模板目录并找到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
}
?>
最后再到模版文件module.php中的评论列表和子评论列表适当位置添加如下挂载点代码: <?php echo useragent($comment['useragent']); ?>
实际网站效果展示