PHP中限制IP段访问、禁止IP提交表单的代码
最近,小编发现有一个云南的网友经常在网站发表一些垃圾信息的评论,由于使用的事DEDECMS构架,系统本身并无禁止IP功能,每天看到这些垃圾评论,尽管不多,但是让人感觉不爽,那么如何来限制呢?
我们只要在feedback.php中添加下面的代码进行判断就可以了。
注意:下边只是一个PHP限制IP的实例代码,如果您打算应用到CMS中,请自行修改,或者如果您正在使用DEDECMS,可以联系本站。
代码如下:
//加IP访问限制
if(getenv('HTTP_CLIENT_IP') && strcasecmp(getenv('HTTP_CLIENT_IP'), 'unknown')) {
$userip = getenv('HTTP_CLIENT_IP');
} elseif(getenv('HTTP_X_FORWARDED_FOR') && strcasecmp(getenv('HTTP_X_FORWARDED_FOR'), 'unknown')) {
$userip = getenv('HTTP_X_FORWARDED_FOR');
} elseif(getenv('REMOTE_ADDR') && strcasecmp(getenv('REMOTE_ADDR'), 'unknown')) {
$userip = getenv('REMOTE_ADDR');
} elseif(isset($_SERVER['REMOTE_ADDR']) && $_SERVER['REMOTE_ADDR'] && strcasecmp($_SERVER['REMOTE_ADDR'], 'unknown')) {
$userip = $_SERVER['REMOTE_ADDR'];
}
//限制ip
if ($userip=='27.37.188.128'){
header("location:http://sc.jb51.net");//被禁止后跳转到脚本之家站
exit;
}
//限制ip段
$ip_arr = explode('.', $userip);
#限制的ip段,假设是192.168.*.*
if (!(($ip_arr[0] == '192' && $ip_arr[1]=='168') )){
header("location:http://sc.jb51.net");//被禁止后跳转到脚本之家素材站
exit;
}else{
header("location:http://www.jb51.net");//正常IP则直接访问脚本之家首页
exit;
}
?>
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article
R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
1 months ago
By 尊渡假赌尊渡假赌尊渡假赌
How Long Does It Take To Beat Split Fiction?
4 weeks ago
By DDD
R.E.P.O. Save File Location: Where Is It & How to Protect It?
4 weeks ago
By DDD
Two Point Museum: All Exhibits And Where To Find Them
1 months ago
By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)
