Show DevBest Ip ban

Status
Not open for further replies.

Khalil

IDK
Dec 6, 2011
1,642
786
Hello everyone, just tought i'd share this small script i found ealier, and using for .

So, the code is (you may just put this as ban.php in your functions file and then use the include function to include it into the page):
PHP:
<?php
  $ip_ban_array = array(
    'FIRST IP',
    'SECOND IP',
    'THIRD IP'
    );
   
  $hostname_ban_array = array(
    'HOSTNAME-1',
    'HOSTNAME-2',
    'HOSTNAME-3'
    );   
function check_ban() {
    if (getenv("HTTP_CLIENT_IP")) $ip = getenv("HTTP_CLIENT_IP");
    else if(getenv("HTTP_X_FORWARDED_FOR")) $ip = getenv("HTTP_X_FORWARDED_FOR");
    else if(getenv("REMOTE_ADDR")) $ip = getenv("REMOTE_ADDR");
    else $ip = "0.0.0.0";
    $host = gethostbyaddr($ip);
 
    $ip_ban_array = array(
    'AN IP TO BAN HERE'
    );
 
    $hostname_ban_array = array(
    'eu.tachyon.net',
    'ttnet.net.tr',
    'meteksan.net.tr',
    'metu.edu.tr',
    'doruk.net.tr',
    'belbone.be',
    'skylogicnet.com',
    'telsim.com.tr',
    'titannetworks.nl'
    );
 
    if (is_array($ip_ban_array)) {
        if (in_array($ip, $ip_ban_array)) {
            die("Your ip have been banned from the website.");
        }
    }
 
    if (is_array($hostname_ban_array)) {
 
        foreach ($hostname_ban_array as $ban_host) {
 
            if (preg_match("/".$ban_host."\b/i", $host)) {
            die("Your Hostname is banned!");
            }
        }
    }
 
}
?>

Then go to your index page or home page, and just include this simple line:
PHP:
<?php check_ban() ?>

Hope you guys like it, if you have any problems with it just pm me pr reply to this thread.

-Khalil
 

Beast

Posting Freak
Sep 15, 2011
625
163
Good release, deff going to use it with my minecraft cms also going to convert it to work with mysql
 

TesoMayn

Boredom, it vexes me.
Oct 30, 2011
1,482
1,482
You should make this into a MySQL, making it easier to ban and unban. :p
 

lepos

thinking about you. yes you
Dec 11, 2011
2,024
687
I like it, I will definitely be using this.

Great work/releases mate.
 

Mee

Member
May 4, 2012
232
28
IP deny manager or

.htaccess

put a line similar to this line:

Deny from 222.154.
 

Khalil

IDK
Dec 6, 2011
1,642
786
IP deny manager or

.htaccess

put a line similar to this line:

Deny from 222.154.

The ip ban from .htaccess is used by "newbs", this method is much more advanced, otherwise i would have posted the htacess one.
 

Khalil

IDK
Dec 6, 2011
1,642
786
No like username ban script connected to the database.

PHP:
<?php
require_once "your config/global file";
$sql = mysql_query("SELECT * FROM YOUR BANS TABLE WHERE value = '".$username."'");
  $b = mysql_fetch_assoc($sql);
$row_ban = mysql_num_rows($sql);
$stamp_now = mktime(date('H:i:s d-m-Y')); // Date of the expire should be set from your bans table.
$stamp_expire = $b['expire']; // Date of expire should be also set from your bans table.
$expire = date('d/m/Y H:i:s', $b['expire']);
if($stamp_now < $stamp_expire){
$erreur = "Your account has been banned!";
}
?>
 

Li1M0ST3Rz

I <3 Bianca
Sep 13, 2010
269
166
PHP:
<?php
require_once "your config/global file";
$sql = mysql_query("SELECT * FROM YOUR BANS TABLE WHERE value = '".$username."'");
  $b = mysql_fetch_assoc($sql);
$row_ban = mysql_num_rows($sql);
if($stamp_now < $stamp_expire){
$erreur = "Your account has been banned!";
}
?>
ok now add it wiith a rank of -1
 

Ecko

23:37 [autobots] -!- eckostylez [[email protected]]
Nov 25, 2012
1,399
962
The ip ban from .htaccess is used by "newbs", this method is much more advanced, otherwise i would have posted the htacess one.
I disagree.

If you are the administrator of a server, you should be denying at the firewall level. If not, then as root you should be denying at the OS level. If you are not root, then you deny at the server level. Denying at the script level should be the last option.

Firewall/Hardware->OS->Server(Apache)->PHP

If you are denying via .htaccess (Apache) then that means no time/resources wasted to load, compile, and execute the PHP script that is performing the same function.
 
Status
Not open for further replies.

Users who are viewing this thread

Top