Jump to content

Banning IPs


shoaibi

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

???
Link to comment
https://forums.phpfreaks.com/topic/16295-banning-ips/
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....
Link to comment
https://forums.phpfreaks.com/topic/16295-banning-ips/#findComment-67611
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,
Link to comment
https://forums.phpfreaks.com/topic/16295-banning-ips/#findComment-67615
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?
Link to comment
https://forums.phpfreaks.com/topic/16295-banning-ips/#findComment-67626
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]
Link to comment
https://forums.phpfreaks.com/topic/16295-banning-ips/#findComment-67630
Share on other sites

Archived

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

×
×
  • Create New...

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.