WeberDev.com PHP and MySQL Code

LOG IN
BEGINNER GUIDESPHP CLASSESCODE SEARCHARTICLES SEARCHPHP FORUMSPHP MANUALPHP FUNCTIONS LISTWEB SITE TEMPLATES
Start typing to search for PHP and MySQL Code Snippets and Articles Search
Submit a code Example / Snippet Join us on FaceBook
Submit a code Example / Snippet Submit Your Code
Poker Tournaments Poker Tournaments
Poker Guide for Developers Poker Guide for Developers
Search Engine Optimization Monitor SEO Monitor
Web Site UpTime Monitor UpTime Monitor
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 Resources
Web Development Content
Internet Security Software
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
פרייסז - הכח לקנות עובר לידיים שלך
Texas Holdem Poker Evangelists

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

Submit your own code examples  Submit your own code examples 
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