|
|
|
| Title : |
Blacklist IPs - Simple way to blacklist IP's, good for instance when you want to stop certain IP ranges known to be spammers.
|
| Categories : |
PHP, Security |
 Alix Axel |
| Date : |
Apr 28th 2009 |
| Grade : |
1 of 5 (graded 1 times) |
| Viewed : |
2827 |
| File : |
No file for this code example. |
| Images : |
No Images for this code example. |
|
| Search : |
More code by Alix Axel |
|
| Action : |
Grade This Code Example
|
|
| Tools : |
My Examples List |
|
|
|
|
|
|
|
|
|
|
Like this code?
Show the author your appreciation.
|
| |
| <?php
function IP_Blacklist($minimum = null, $maximum = null)
{
$ip = ip2long($_SERVER['REMOTE_ADDR']);
if (is_null($minimum) === false)
{
$minimum = explode('.', $minimum);
foreach ($minimum as $key => $value)
{
$minimum[$key] = ($value == '*') ? 0 : $value;
}
$minimum = ip2long(implode('.', $minimum));
if ($ip >= $minimum)
{
return false;
}
}
if (is_null($maximum) === false)
{
$maximum = explode('.', $maximum);
foreach ($maximum as $key => $value)
{
$maximum[$key] = ($value == '*') ? 255 : $value;
}
$maximum = ip2long(implode('.', $maximum));
if ($ip <= $maximum)
{
return false;
}
}
return true;
}
?> | |
Usage $_SERVER['REMOTE_ADDR'] = 195.22.23.24:
| <?php
IP_Blacklist('195.22.23.*'); // false, blacklisted
IP_Blacklist('195.0.0.0', '195.255.255.255'); // false, blacklisted
IP_Blacklist('195.22.23.25', '195.22.23.255'); // true, clean
if (IP_Blacklist('195.22.23.*', '195.22.23.*') === false)
{
die('Nice try spammer.');
}
?> | | |
|
| A damaged image generator (class) for validating text.
CAPTCHA - Completely Automated Public Turing test to tell Computers and Humans Apart Categories : PHP, PHP Classes, Security, GD image library, Security | | | Function to generate readable/remeberable random password Categories : PHP, Security, Security | | | A PHP function to encrypt and decrypt a number or string or a combination of the two. Categories : PHP, Encryption, Security | | | Generate image with random number (CAPTCHA) Categories : PHP, GD image library, Graphics, Security | | | A Simple Script that stores encrypted messages in databases Categories : PHP, Databases, MySQL, Security | | | Form Security - Match A Value For Success Categories : PHP, Authentication, HTML and PHP, Sessions, Security | | | Protect your email links from being spidered by spam email robots! Categories : PHP, Security, Mail, Email | | | send_mail function to defeat Header Injection Hacking/Spamming Categories : PHP, Email, Form Processing, Security | | | Encoding data using PGP via PHP's proc_* functions Categories : Cryptography, Security, Email, PHP, PGP | | | Creates a CAPTCHA image in PHP, which displays 5 numbers stored in a session. Categories : PHP, GD image library, Form Processing, Security | | | Dollar Serial Number Validator Categories : PHP, Security, Algorithms | | | IPTables Bandwidth statics Categories : PHP, Security, Network | | | Random Password Generator Categories : PHP, Strings, Security | | | Passgen: Automatically generate mixed case alpha numeric passwords Categories : PHP, Security | | | A very simple PHP single password cookie based login without usernames. Categories : PHP, Cookies, Security, Beginner Guides | |
| |
| |
|