Jump to content


Photo

Banning IPs


  • Please log in to reply
9 replies to this topic

#1 shoaibi

shoaibi
  • Members
  • PipPip
  • Member
  • 21 posts

Posted 02 August 2006 - 06:21 AM

Okay look at me, i am a newbie, not quite one, but still one of the beginners, i know about .htacess and all that. I wanna allow one one country people to view my site.
You people tell me what's the best and cheapest method to do that.
And is there a place from where i can get the ip ranges so that i cna do something like that:
allow Tha.tIP.Ra.n.ge
deny all

???

#2 BillyBoB

BillyBoB
  • Members
  • PipPipPip
  • Advanced Member
  • 630 posts

Posted 02 August 2006 - 06:39 AM

um i dont really get your question but are u trying to ban ips from ur whole site
if so are you using php and mysql (you dont need mysql but php) ?

#3 shoaibi

shoaibi
  • Members
  • PipPip
  • Member
  • 21 posts

Posted 02 August 2006 - 06:40 AM

um i dont really get your question but are u trying to ban ips from ur whole site
if so are you using php and mysql (you dont need mysql but php) ?

I want to ban all ips from my whole site except then a few countries specified....

#4 BillyBoB

BillyBoB
  • Members
  • PipPipPip
  • Advanced Member
  • 630 posts

Posted 02 August 2006 - 06:42 AM

can i ask why you want to ban all people except for a few countries

i dont really know how to ban all except a few tho

#5 shoaibi

shoaibi
  • Members
  • PipPip
  • Member
  • 21 posts

Posted 02 August 2006 - 06:44 AM

can i ask why you want to ban all people except for a few countries

i dont really know how to ban all except a few tho

Well nothing much, except that its a site meant only for those people. and then also i wanna save bandwidth. think of it as a download site which it actually is, but thought the material posted is neither copyrighted nor offensive, but its just meant for the people of those countries, i.e. those who support me,

#6 manmadareddy

manmadareddy
  • Members
  • PipPipPip
  • Advanced Member
  • 50 posts

Posted 02 August 2006 - 06:45 AM

I hope these two sites will be helpful.
http://www.maxmind.com
or
http://www.geobytes.com which contains IP to geo lookup

#7 Guest_ryen_*

Guest_ryen_*
  • Guests

Posted 02 August 2006 - 06:47 AM

HERE:

http://www.phptutori..._countries.html




#8 shoaibi

shoaibi
  • Members
  • PipPip
  • Member
  • 21 posts

Posted 02 August 2006 - 06:49 AM

Thanks manmadareddy and ryen though ryen seemed to be more accurate ;) See you all later when i will have problem regarding these ;)

#9 shoaibi

shoaibi
  • Members
  • PipPip
  • Member
  • 21 posts

Posted 02 August 2006 - 06:52 AM

HERE:

http://www.phptutori..._countries.html




NOTE: Sorry got the answer!!!!!!


and that's for to respond in a certain why, suppose that i want to repond to US only and Display a meesage showing that your ip is not allowed to visit then i would have to download the US database as well as others?
Or i can downlaod US one and then set a if else check?

#10 BillyBoB

BillyBoB
  • Members
  • PipPipPip
  • Advanced Member
  • 630 posts

Posted 02 August 2006 - 06:56 AM

say u wanted only usa to be allowed

then dl usa database import it and then code a page like

 <?
function iptocountry($ip) {   
    $numbers = preg_split( "/\./", $ip);   
    include("ip_database.php");
    $code=($numbers[0] * 16777216) + ($numbers[1] * 65536) + ($numbers[2] * 256) + ($numbers[3]);   
    foreach($ranges as $key => $value){
        if($key<=$code){
            if($ranges[$key][0]>=$code){$two_letter_country_code=$ranges[$key][1];break;}
            }
    }
    if ($two_letter_country_code==""){$two_letter_country_code="unkown";}
    return $two_letter_country_code;
}
$IPaddress=$_SERVER['REMOTE_ADDR'];
$two_letter_country_code=iptocountry($IPaddress);

if ($two_letter_country_code=="US"){
     echo("Access granted");
    }else{
     echo("Access Denied");
      die();
    }
?>





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users