Question:

I need to ban an ip address. . . ?

by  |  earlier

0 LIKES UnLike

on the game i made (in php) people keep coming on and advertising other games and i want to ip ban these people. I have been doing this through the .htaccess file but because im the only one with access to that file, they advertise when im offline. is there a script that will let me and the other admins ban someones ip. If you can show me an ip ban script (preferably in php and, or MySQL) or redirect me to a site, i would be very grateful.

 Tags:

   Report

1 ANSWERS


  1. Since you have Php and MySQL, it is easy!

    Just after the <body> tag:

    <?php

    $ip = GetHostByName($REMOTE_ADDR);

    $host = @getHostByAddr( $ip ); // Host address

    $ip_number = sprintf("%u", ip2long($ip)); // from A.B.C.D. to number

    $dotted_ip_address = long2ip($ip_number); // from # to A.B.C.D.

    echo ("IP: " . $ip_number . ", " . $dotted_ip_address . "<br>");

    $res = check_ip ($ip_number);

    if ($res)

    exit();

    ?>

    $ip and $dotted_ip_address is the format x*x.x*x.x*x.x*x

    $ip_number is that ABCD converted into a LONG integer.

    Create a table in mySQL:

    table banned, field ip int (long).

    You store there the banned addresses.

    function check_ip($ip):

    query the DB.  Return true if address is found, false otherwise.

    If IP address is found, the loading of the site stops.

    It would be useful to set a RANGE of IP addresses:

    table banned ip_from, ip_to

    in ip_from: the lowest value of the ip address,

    in ip_to: the highest.

    This will allow you to ban a RANGE of addresses, like

    212.111.222.000 to 212.111.222.999

    Remember that bad posters use a dynamically allocated IP address, where the two or three first groups only stay the same!

Question Stats

Latest activity: earlier.
This question has 1 answers.

BECOME A GUIDE

Share your knowledge and help people by answering questions.
Unanswered Questions