管理员

- 积分
- 1
- 登陆
Warning: Illegal string offset 'loginnum' in /www/wwwroot/kyuanma.com/e/data/tmp/dt_temptext13.php on line 257
次
- 私信
- 注册时间
Warning: Illegal string offset 'registertime' in /www/wwwroot/kyuanma.com/e/data/tmp/dt_temptext13.php on line 261
Warning: date() expects parameter 2 to be long, string given in /www/wwwroot/kyuanma.com/e/data/tmp/dt_temptext13.php on line 261
- 最后登陆时间
Warning: Illegal string offset 'lasttime' in /www/wwwroot/kyuanma.com/e/data/tmp/dt_temptext13.php on line 263
Warning: date() expects parameter 2 to be long, string given in /www/wwwroot/kyuanma.com/e/data/tmp/dt_temptext13.php on line 263
|
由于很多人有一些需求在做国内站的时候,不做国内某个地区的业务的时候,他想屏蔽用户访问网站,我这边以dedecms搜索功能为例子,因为是以前开发的,时间比较有限现在,不重新调整做整站的功能,如果有需要,可以将以下相关代码放入一个php文件,然后在data/common.ini.php里面包含就可以了。
目前网络上有很多资源,例如著名的珊瑚虫ip数据库,但是其文件在本地,得定时更新。我们现在使用淘宝ip数据库,通过json返回的数据来解析ip是否某地区,下面以"上海市"为例:
首页找到dedecms底下plus下的search.php文件,查找以下代码
1 |
if ( $cfg_notallowstr != '' && preg_match( "#" . $cfg_notallowstr . "#i" , $keyword )) |
3 |
ShowMsg( "你的搜索关键字中存在非法内容,被系统禁止!" , "-1" ); |
|
在上面加入
01 |
function get_ip_data(){ |
03 |
$ip = json_decode( $ip ); |
07 |
$data = ( array ) $ip ->data; |
08 |
if ( $data [ 'city' ]== '上海市' && !isCrawler()){ |
12 |
/* header("location:".getenv("HTTP_REFERER")); // 返回其调用页面 */ |
17 |
function isCrawler() { |
31 |
"Java (Often spam bot)" , |
42 |
"Alexa (IA Archiver)" , |
53 |
"The web archive (IA Archiver)" , |
62 |
if (in_array( strtolower ( $_SERVER [ 'HTTP_USER_AGENT' ]), $spiderSite )){ |
70 |
function get_client_ip() |
73 |
if (isset( $_SERVER [ "HTTP_X_FORWARDED_FOR" ])){ |
74 |
$realip = $_SERVER [ "HTTP_X_FORWARDED_FOR" ]; |
75 |
} else if (isset( $_SERVER [ "HTTP_CLIENT_IP" ])) { |
76 |
$realip = $_SERVER [ "HTTP_CLIENT_IP" ]; |
78 |
$realip = $_SERVER [ "REMOTE_ADDR" ]; |
81 |
if ( getenv ( "HTTP_X_FORWARDED_FOR" )){ |
82 |
$realip = getenv ( "HTTP_X_FORWARDED_FOR" ); |
83 |
} else if ( getenv ( "HTTP_CLIENT_IP" )) { |
84 |
$realip = getenv ( "HTTP_CLIENT_IP" ); |
86 |
$realip = getenv ( "REMOTE_ADDR" ); |
93 |
ShowMsg( "你的IP被禁止!" , "-1" ); |
|
我将函数直接写在search.php文件中,大家不要学我,这会导致原来的文件代码有些杂乱,建议使用包含函数文件的方式。
保存文件后,你让上海市的朋友访问,系统就会提示"你的IP被禁止!"的提示,赶紧试试吧。
|
|