Valhalla Legends Archive

Programming => Web Development => Topic started by: Crazy_X on December 21, 2003, 11:20 PM

Title: IPBan :
Post by: Crazy_X on December 21, 2003, 11:20 PM
<?php
$banned_ip = array();
$banned_ip[] = '*.*.*.**1';
$banned_ip[] = '*.*.*.**2';
$banned_ip[] = '*.*.*.**3';
$banned_ip[] = '*.*.*.**4';

foreach($banned_ip as $banned) {
   $ip = $_SERVER['REMOTE_ADDR'];
   if($ip == $banned){
       echo "Error 04, Banned.";
       exit();
   }
}
//blah
?>

Has anyone written anything better? Just wrote this up, excuse me if its been done before but it works for me.
Title: Re:IPBan :
Post by: Forged on December 22, 2003, 06:09 PM
If I were you I would write all of the wanted ipbans to a textfile.  And then a code that would let you ban new ips from a webpage as opposed to having to login to my ftp and editing my file every time you find another fucker.

&Edited
Title: Re:IPBan :
Post by: AssassinRC on December 22, 2003, 06:44 PM
Or MySQL. Just a thought.
Title: Re:IPBan :
Post by: Forged on December 22, 2003, 06:49 PM
Mysql would be the same thing with extra code...
Title: Re:IPBan :
Post by: Archangel. on December 25, 2003, 12:01 PM
<?
if (ereg("IP Here",$REMOTE_ADDR))
{
echo "your banned ."; exit(); }
?>
Title: Re:IPBan :
Post by: CrAzY on December 25, 2003, 06:07 PM
Hmmm, I'll Right you a Script.

<?php $db="HelloWorld"; //MySQL Database here$username="Admin"; //MySQL Username$password="JohnSmith"; //MySQL Password@mysql_connect('localhost', $username, $password);@mysql_select_db($db);$ip=$_SERVER['REMOTE_ADDR']);$ip2=mysql_query("Select `ip` From $db");if($ip==$ip2){echo("Your IP Is Invalid!")}else{echo("All the data of the page go's here");}?>



I think I may have messed up, if I did, some one correct me.  (Sorry, in a hurry to go some where.)
Title: Re:IPBan :
Post by: Banana fanna fo fanna on December 25, 2003, 06:45 PM
Yeah there isn't a loop.
Title: Re:IPBan :
Post by: Archangel. on December 26, 2003, 06:54 PM
I will write u a better one... just wait 20 min lol..
Title: Re:IPBan :
Post by: Archangel. on December 26, 2003, 07:03 PM
U can use this to:
   <?php
   $IP=$_SERVER["REMOTE_ADDR"];
   $host = gethostbyaddr($_SERVER['REMOTE_ADDR']);
   $host=array("204.22.109.34.router34.isp.net", "216.229.45.11");
   $test=$IP.".".$lh;
   if(in_array($test, $host) || in_array($host, $IP)) {
   header("Location: http://yoursite.com/banned.html"); }
   ?>
Title: Re:IPBan :
Post by: Banana fanna fo fanna on December 26, 2003, 10:34 PM
Nope sorry.
Title: Re:IPBan :
Post by: Arta on December 27, 2003, 05:01 PM
Using gethostbyaddr() will make your page load very slowly if it can't find the name. It takes ages to time out.