IP Banning

IP BanningIntroduction

Like many webmasters, you're bound to attract some annoying visitors, such as spammers. This is inevitable, but you can fight back. The simplest method of cyber combat is banning the IP, although this is not the most powerful method it works 90% of the time. Continue reading to figure out how this process works, or if you’re a codeshark scroll down to the bottom of the page.

Overview

With an already gathered IP address, we're going to ban an annoying visitor! We’re going to be using arrays and loops in this process.

Step by Step Tutorial....

This tutorial requires you to have the IP address of the visitor, so I assume you already know how to gather the IP. To be sure, I’ll post the code:

<?php $ip = $_SERVER['REMOTE_ADDR'];

Now, let’s finish off the rest of the variables, which will be in array format and an extension of the ray. Notice the code posted below. You can add more IP addresses in the array by separating them with a comma and start the semi quotations. The count function will count the variables in the array.

$ban = array('333.333.333.333',’111.111.111.111’);
$count = count($ban);

After that, we need to start the loop which will require the count function. If you don’t know how to use loops I suggest you read up on them.

for ($i=0; $i<$count; $i++) {
if($ip == $ban[$i]) { die("I'm sorry, you've been banned. $ip"); } } ?>

Final product

<?php
$ip = $_SERVER['REMOTE_ADDR'];
$ban = array('333.333.333.333','68.225.34.86');
$count = count($ban);
for ($i=0; $i<$count; $i++) {
if($ip == $ban[$i]) { die("I'm sorry, you've been banned. $ip"); }
}
?>

Enjoy !


Related Articles

  • IP Banning
    1. Make a new text file and name it .htaccess or open one you already have.
    2. Find out the persons IP address and substitute it for 000.000.000.000.
    To deny access..
    deny from 000.000.000.000
    To allow access..
    allow from 000.000.000.000
    To ban everyone..
    deny from all
    To add mor....
  • How to Develop a Competent SEO Strategy
    Formulating an effective SEO strategy is not as easy as it seems to be. It cannot be developed magically. It requires careful planning. The prime objective of every internet entrepreneur is to optimize their site to attract more traffic.
  • Creating a Robots.txt file
    Some people believe that they should create different pages for different search engines, each page optimized for one keyword and for one search engine. Now, if you do decide to create such pages, there is one issue that you need to be aware of...
  • Surviving In The Web Without Google
    New sites, which are not indexed by Google, face a tough challenge to attract visitors. This article outlines the techniques to get hits without using Google SERPs.
  • Link popularity improvement tutorial
    Improving your link popularity is a big part of optimizing your website for search engines. Many webmasters ignore this very rewarding process. The most common reason for this is the time it takes. Many webmasters just don
  • See the Destruction of Email Messaging from the Comfort of Your Home!!!
    Spam and other commercial messages are throttling emails simple appeal. And no-one is offering a credible remedy.
  • SEOs Who Party Like it's 1999
    Search engine optimization has come full circle in the last couple of years.
    Back in the mid 1990s it was easy to achieve high search engine rankings. Just tweak your META tags and site copy with keywords and submit. Then, as more and more webmasters started to catch on to META Tags, it became m...
  • 10 Easy Ways to Get Top 10 Search Engine Optimization Rankings
    1. Chose your Keywords Carefully Once you have chosen your business and purchased a domain name the next step before submitting your site to search engines is to find useful and relevant keywords. Without this step your website will get lost in the millions of websites competing for your business....
  • Planning For Search Engine Positioning - 13 Basic Steps To A Successful Internet Positioning Strategy
    You built a great looking website but where is the traffic you hoped to generate? Too often I find very expensive corporate and business websites that have given little thought to how the site will play in the search engines...

Contact Web Design Outsource and get started today

Need Website Designing, Development, Redesigning, Maintenance and SEO services or help growing your company's web presence? Request a free Quote Now.