LAMP之路

不积跬步,无以至千里!

修正discuz!官方IP地址不显示地区的方法

2012-10-18 一抹阳光 网站程序

官方的经常显示unknown,替换纯真的上去发现 GBK的论坛正常 UTF8的不正常,看一下官方的代码,原来官方支持纯真数据库的啊。

搜索 “纯真ip数据库”下载并上传到论坛ipdata目录上去 并命名为wry.dat 可以自定义,自己看下去就知道
修改文件
include/misc.func.php line29
查找

$tinyipfile = DISCUZ_ROOT.’./ipdata/tinyipdata.dat’;
$fullipfile = DISCUZ_ROOT.’./ipdata/wry.dat’;
if(@file_exists($tinyipfile)) {
$return = convertip_tiny($ip, $tinyipfile);
} elseif(@file_exists($fullipfile)) {
$return = convertip_full($ip, $fullipfile);
}

对应替换

$tinyipfile = DISCUZ_ROOT.’./ipdata/tinyipdata.dat’;
$fullipfile = DISCUZ_ROOT.’./ipdata/wry.dat’;
//if(@file_exists($tinyipfile)) {
// $return = convertip_tiny($ip, $tinyipfile);
//} elseif(@file_exists($fullipfile)) {
$return = convertip_full($ip, $fullipfile);
require_once DISCUZ_ROOT.’include/chinese.class.php’;
$chs = new Chinese(‘GBK’, $GLOBALS['charset']);
$return = addslashes($chs->Convert(urldecode($return)));
//}

那些if之所以不要因为你的文件已经上传了~不需要检测。当然根据你喜欢你也可以加上去
if(@file_exists($fullipfile)) {
$return = convertip_full($ip, $fullipfile);
require_once DISCUZ_ROOT.’include/chinese.class.php’;
$chs = new Chinese(‘GBK’, $GLOBALS['charset']);
$return = addslashes($chs->Convert(urldecode($return)));
}

这样已经完成了哦~~查看一下用户信息
对于GBK用户应该可以省略以下三段代码 具体你们试试
require_once DISCUZ_ROOT.’include/chinese.class.php’;
$chs = new Chinese(‘GBK’, $GLOBALS['charset']);
$return = addslashes($chs->Convert(urldecode($return)));

—————————-
如果想在帖子里面或者在线列表中使用参考如下
主要调用这一句
查找 viewthread.php
$post['regdate'] = gmdate($dateformat, $post['regdate'] + $timeoffset * 3600);
$post['lastdate'] = gmdate($dateformat, $post['lastactivity'] + $timeoffset * 3600);
下面添加
[code]
require_once DISCUZ_ROOT.'include/misc.func.php';
$post['showipaddress'] = convertip($post['useip']);

然后你在模板文件 viewthread_node.htm
添加 $post[showipaddress] 就可以显示某某省市

查找$pluginhooks[viewthread_sidebottom][$postcount]}
下面添加
<p id="showipaddress">$post[showipaddress]</p>
---------------------
在线显示比较简单
打开 member.php
查找
<code>while($online = $db-&gt;fetch_array($query)) {
$online['lastactivity'] = gmdate($timeformat, $online['lastactivity'] + $timeoffset * 3600);
$online['action'] = $actioncode[$online['action']];
$online['subject'] = $online['subject'] ? cutstr($online['subject'], 35) : NULL;
$online['ip'] = $online['ip1'].'.'.$online['ip2'].'.'.$online['ip3'].'.'.$online['ip4'];
</code>
下面添加
<code>require_once
DISCUZ_ROOT.'include/misc.func.php';
$online['ip'] .= convertip($online['ip']);</code>

-----------------------------
第二种 比较喜欢
查找

<code>while($online = $db-&gt;fetch_array($query)) {
$online['lastactivity'] = gmdate($timeformat, $online['lastactivity'] + $timeoffset * 3600);
$online['action'] = $actioncode[$online['action']];
$online['subject'] = $online['subject'] ? cutstr($online['subject'], 35) : NULL;
$online['ip'] = $online['ip1'].'.'.$online['ip2'].'.'.$online['ip3'].'.'.$online['ip4'];</code>

在下面添加
<code>require_once DISCUZ_ROOT.'include/misc.func.php';
$online['showipaddress'] = convertip($online['ip']);
if($adminid $online['ip3'] = $online['ip4'] ="XXX";
}
$online['ip'] = $online['ip1'].'.'.$online['ip2'].'.'.$online['ip3'].'.'.$online['ip4'].$online['showipaddress'];</code>

然后打开模板whosonline
更改为
<code>{subtemplate header}</code>
<div id="nav"><a href="$indexname">$bbname</a> » {lang whosonline}</div>
<div id="wrap">
<div>
<div>
<h1>{lang whosonline}</h1>
<div>
<table summary="" cellspacing="0" cellpadding="0">
<thead>
<tr>
<td>{lang username}</td>
<td>{lang time}</td>
<td>{lang online_action}</td>
<td>{lang online_in_forum}</td>
<td>{lang online_in_thread}</td>
<td>{lang online_ip}</td>
</tr>
</thead>
<tbody><!--{loop $onlinelist $online}-->
<tr>
<td><!--{if $online['uid']}--><a href="space.php?uid=$online[uid]">$online[username]</a><!--{else}-->{lang guest}<!--{/if}--></td>
<td>$online[lastactivity]</td>
<td>$online[action]</td>
<td><!--{if $online['fid']}--><a href="forumdisplay.php?fid=$online[fid]">$online[name]</a><!--{/if}--></td>
<td><!--{if $online['tid']}--><a href="viewthread.php?tid=$online[tid]">$online[subject]</a><!--{/if}--></td>
<td>$online[ip]</td>
</tr>
</tbody>
</table>
<div>$multipage</div>
</div>
</div>
</div>
</div>
{subtemplate footer}