Jump to content

Archived

This topic is now archived and is closed to further replies.

shoaibi

Banning IPs

Recommended Posts

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

???

Share this post


Link to post
Share on other sites
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) ?

Share this post


Link to post
Share on other sites
[quote author=BillyBoB link=topic=102679.msg407857#msg407857 date=1154500746]
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) ?
[/quote]
I want to ban all ips from my whole site except then a few countries specified....

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
[quote author=BillyBoB link=topic=102679.msg407862#msg407862 date=1154500944]
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
[/quote]
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,

Share this post


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

Share this post


Link to post
Share on other sites
Guest ryen
HERE:

http://www.phptutorial.info/iptocountry/identification_of_specific_countries.html


Share this post


Link to post
Share on other sites
Thanks manmadareddy and ryen though ryen seemed to be more accurate ;) See you all later when i will have problem regarding these ;)

Share this post


Link to post
Share on other sites
[quote author=ryen link=topic=102679.msg407869#msg407869 date=1154501246]
HERE:

http://www.phptutorial.info/iptocountry/identification_of_specific_countries.html



[/quote]
[color=red]
[size=10pt][size=10pt][size=10pt][size=10pt][size=10pt][size=10pt][u][b]NOTE: Sorry got the answer!!!!!![/b][/u][/size][/size][/size][/size][/size][/size][/color]

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?

Share this post


Link to post
Share on other sites
say u wanted only usa to be allowed

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

[code]
<?
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();
    }
?>
[/code]

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.