WeberDev.com PHP and MySQL Code

LOG IN
BEGINNER GUIDES  |  PHP CLASSES  |  CODE SEARCH  |  ARTICLES SEARCH  |  PHP FORUMS  |  PHP MANUAL  |  PHP FUNCTIONS LIST  |  WEB SITE TEMPLATES
Start typing to search for PHP and MySQL Code Snippets and Articles Search
Submit a code Example / Snippet Submit Your Code
Search Engine Optimization Monitor SEO Monitor
Web Site UpTime Monitor UpTime Monitor
WeberDev's Monthly code contest PHP Code Contest
Your Personal Examples List My Favorite Examples
Your Personal Articles List My Favorite Articles
Edit Account Info Update Your Profile
PHP Code Search
Web Development Forums
Learn MySQL Playing Trivia
PHPBB2 Templates
Web Development Index
Web Development Resources
Web Development Content
PHPClasses
PHP Editor
PHP Jobs
Vision.To Design
Ajax Tutorials
PHP Programming Help
PHP/MySQL Programming
Webmaster Resources
Webmaster Forum
XML meta language
website builder
Mobile Dev World

Go Back Add a Comment Send this example to a friend Add this Article to your personal favoritest for easy future access to your favorite Code Examples and Articles. Submit a code example Print this code example.
BACK ADD A COMMENT SEND TO A FRIEND ADD TO MY FAVORITES ADD CODE EXAMPLES PRINT
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 Click here to Update Your Picture
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.
Submit your own code examples 
 

<?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