|
|
|
| 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 : |
1549 |
| 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 | | | PHP Cookies - Simple cookie write/read methods that allow basic encryption Categories : PHP, Cookies, Security, Encryption | | | A simple PHP login script that you can modify to suite your needs. It use a session to store data in a session file submited by the page. Categories : PHP, Sessions, Security, Authentication | | | Easily Grant Temporary SSH Access to yourself when in remote location Categories : PHP, Linux, Cron, Security | | | Dollar Serial Number Validator Categories : PHP, Security, Algorithms | | | PHP Function to Encrypt/Decrypt a string without a known key. The string itself has his own different key for every character. Categories : PHP, Algorithms, Security, Authentication, Encryption | | | Session Validation Methods (Security Checks) Categories : PHP, Sessions, Security | | | MD5 secured login Categories : PHP, Java Script, Authentication, Security | | | filter untrusted GET and POST variables and create trusted variable of same name Categories : PHP, Global Variables, Security | | | Creates a CAPTCHA image in PHP, which displays 5 numbers stored in a session. Categories : PHP, GD image library, Form Processing, Security | | | Password using php, Javascript, and html form Categories : Security, PHP, Authentication, Java Script | | | A few functions to create random passwords. Categories : PHP, Security, Strings | | | Protect your email links from being spidered by spam email robots! Categories : PHP, Security, Mail, Email | | | Antispoof - a class to help prevent people hi-jacking and misusing parts of a website Categories : PHP, PHP Classes, Security | | | Generating and Matching Secure and Strong Password Hash Categories : PHP, PHP Classes, Cryptography, Security | |
|
|