Posts Tagged ‘BAN’

IP BAN – PHP/MySQL Checking Script

Tuesday, June 2nd, 2009

This is a small script can be used to redirect banned ip address users from your website, what it does exactly is calls the function “ipbanCheck” checks the database “ipban” for a matching IP Addresses of the current users IP Address then redirects them via javascript to =  http://www.google.co.uk/search?q=GTFO :)

Database Setup:
1) log into phpMyAdmin, select the database you want the table built into.
2) select “SQL” from the tab menu, run the below.

SQL code:

CREATE TABLE ipban ( ID int(12) NOT NULL auto_increment, IP varchar(25) NOT NULL default '', PRIMARY KEY (ID) ) TYPE=MyISAM;

3) should output “executed successfully” etc. now select the table “ipban” then select “Insert” from tab menu now enter the IP Address your want to BAN in the field “IP”.

Usage:
Reason why i’m out putting the echo’s with outs like: “&conn=YES&IP=$ip” is for Flash loadVars integration. To use this function “ipbanCheck” just call it like so;

require_once 'ipban.php'; //file path to the file
ipbanCheck(); //check function

Example
http://3l3373.com/dl/tutorials/ipBan/check.php – You should see an output of  “&conn=YES&IP=93.97.40.201ban=NO&” unless You have been BANNED :)

PHP Code

<?php

/* 

/////////////////////////////////
IP BAN - Kurt Grung - 3L3373.com
/////////////////////////////////

Database Setup:
1) log into phpMyAdmin, select the database you want the table built into.
2) select "SQL" from the tab menu, run the below SQL code:
CREATE TABLE ipban ( ID int(12) NOT NULL auto_increment, IP varchar(25) NOT NULL default '', PRIMARY KEY (ID) ) TYPE=MyISAM;
3) should output "executed successfully" etc. now select the table "ipban" then select "Insert" from tab menu now enter the IP Address your want to BAN in the field "IP".

Usage:
Reason why i'm out putting the echo's with outs like: "&conn=YES&IP=$ip" is for Flash loadVars integration.

To use this function "ipbanCheck" just call it like so;  

require_once 'ipban.php'; //file path to the file
ipbanCheck();

*/

function ipbanCheck(){

 //config
 $ip = $_SERVER['REMOTE_ADDR'];
 $redirectURL = "http://www.google.co.uk/search?q=GTFO";

 //db.conn
 $dbHost = "";
 $dbUser = "";
 $dbPass = "";
 $dbName = "";

 //connection sucsessful?
 $link = mysql_connect($dbHost, $dbUser, $dbPass, $dbName);
 if(!$link){
 die('&conn=NO&');
 die('Could not connect: '.mysql_error());
 }

 echo '&conn=YES&IP='.$ip;

 //db.conn
 mysql_connect($dbHost, $dbUser, $dbPass) or die(mysql_error());
 mysql_select_db($dbName) or die(mysql_error());
 $s=$_SERVER["REMOTE_ADDR"];

 //draws IP address of visitor
 $ipbancheck="SELECT * from ipban where IP='$s'";
 $ipbancheck2=mysql_query($ipbancheck);
 while($ipbancheck3=mysql_fetch_array($ipbancheck2)){
 $IPBANNED=$ipbancheck3[IP];
 }
 //above lines check to see if user Ip is in banned IPs
 if ($IPBANNED){
 //redirect user..
 echo "<script> setTimeout(location.href=\"$redirectURL\", 1); </script>";
 }else{
 echo 'ban=NO&';
 //put content you want unbanned users to see here
 }
}

?>
Vote in HexoSearch
  • Categories

  • Recent Comments

  • Recent Posts

  • Tumblr

  • Flickr Recent Photos

    cherry tree woodstonja_gravestonesPockey Chimp FlavourAUTO FTW! :)darkdaystayouttiger kittenbirdofpreyfirst photo i took with my 1000dself_portrait_02
  • XFIRE (wkly hrs pld)

  • Last.FM

  • Tags

    .MP4 Actionscript Action Script Advertising AS2 AS3 backtrack BT4 bug Call of Duty capcom centOS COD count down countdown crossdomain Eyeblaster eyeblaster HD f4v Flash h264 HD high definition Install internet explorer Linux loadMovie MIME MIME Types MW2 Nazi Zombies pc PHP ports preloader release date rich media shared objects SWF SWFOBJECT timer torrents Video video/mp4 win7