1.后台添加“IP归属选择”开关,网络方式为从chinaz.com查询获得地理位置信息,本地方式为从本地数据库文件中查询。
2.在
require/common.php文件里添加自定义函数,数据的处理都在这里:
function getipguishu($onlineip) {//2025.12.21
$getUrl = 'https://ip.tool.chinaz.com/'.$onlineip;
$curl = curl_init(); // 初始化curl
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); // 跳过证书检查
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 2); // 从证书中检查SSL加密算法是否存在
curl_setopt($curl, CURLOPT_URL, $getUrl); // 抓取指定网页
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); // curl不直接输出到屏幕
curl_setopt($curl, CURLOPT_HEADER, 0); // 设置header
$data = curl_exec($curl); // 运行curl
curl_close($curl);
$begin=strpos($data,'items-center');
$end=$begin+100;
$str=substr($data,$begin,$end);//截取页面
$encode = mb_detect_encoding($str, array('ASCII','UTF-8','GB2312','GBK','BIG5'));
$string =mb_convert_encoding($str,'GBK',$encode);//使用iconv函数转码在空间论坛无效
$begin2=strpos($string,'ipAddress');
$end2=$begin2+100;
$str2=substr($string,$begin2,$end2);//再次截取页面
$str3=explode('>',$str2);
$str4=explode('<',trim($str3[1]));
$wulidizhi=trim($str4[0]);
$guishu=str_replace('-','',$wulidizhi);
return $guishu;
}
3.修改文件
lib/forum/topicpost.class.php pw_tmsgs
lib/forum/replypost.class.php pw_posts
lib/forum/postmodify.class.php pw_posts
(1)添加变量:global $db_cvtime, $db_ptable, $onlineip, $db_plist
,$db_ipguishu;
(2)获取数据:$guishu=getipguishu($onlineip);//2025.12.21
(3)根据后台开关,判断用网络还是本地方式更新数据
//$ipfrom = $ipTable->getIpFrom($onlineip);
$ipfrom = $db_ipguishu ? $guishu : $ipTable->getIpFrom($onlineip);