开发者

offensive IP Address

开发者 https://www.devze.com 2023-03-27 04:43 出处:网络
I got two suspicious visitors to my website and when I googled their IP a开发者_Python百科ddresses they showed up in one of the offensive IP databases. Is there a way to prevent any offensive IP addre

I got two suspicious visitors to my website and when I googled their IP a开发者_Python百科ddresses they showed up in one of the offensive IP databases.

Is there a way to prevent any offensive IP address from accessing my website?

Thanks


To prevent an IP from accessing your site, put this in the top of your document:

if($_SERVER['REMOTE_ADDR'] == '12.34.56.78')
    die('You have been banned.');

Instead if die() you can also use exit to stop the script,
or header('Location: http://www.google.com') to send them to google.

Because there's a good chance they will resort to proxies, it might be better to link this to a database where you can insert all the IP addresses.


In PHP

$_SERVER['REMOTE_ADDR']

holds the visitors IP-address. You could check that against a list of IP-addresses you'd want to prevent from visiting.

See http://www.php.net/manual/en/reserved.variables.server.php


You can ban visitors by IP in PHP by using $_SERVER['REMOTE_ADDR'] but if you're using Apache server I suggest HTACEESS way.

Use this pattern in your root folder .htaccess file

order allow,deny
deny from 123.45.6.7
deny from 012.34.5.
allow from all


You can use .htaccess file to block and IP address. However, as zerkms said, if they really want to get to your site they'll just use a proxy.

http://www.clockwatchers.com/htaccess_block.html

0

精彩评论

暂无评论...
验证码 换一张
取 消