Forum Moderators: phranque
When I make the compare how much it costs me....
To make the long story short, I want to block the United States.
Thats is the .htaccess file below I use......
________________________
#RemoveHandler .html .htm
AddHandler application/x-httpd-php .php .html .htm
_______________________
This is the code I use on my pages......
I use of have it bookmarked in my favourites bookmarks. I've lost it. I am just looking for the input again but for the united states this time.
______________________
<?php
function iptonumber($ip){
$ip=explode('.', $ip);
return $ip[0]*pow(256, 3)+$ip[1]*pow(256, 2)+$ip[2]*256+$ip[3];
}
$ips=unserialize('a:8366:{i:0;a:2:{s:5:"minip";s:8:"33996344";s:5:"maxip";s:8:"33996351";}i:1;a:2:{s:5:"minip";s:9:"152305664";s:5:..... And the list goes on for a long time...............
:"maxip";s:10:"3577603055";}}');
foreach($ips as $ip){
if (($number <= $ip['maxip']) and ($number >= $ip['minip'])){
echo "Sever errored\n";
exit;
}
}
?>
-----------------
A comment on this code, though:
The list of US IP addresses will be huge; I believe China is about to overtake the US, but either way, the list is very big. And as you know, IP address blocks are de-allocated and re-allocated fairly frequently.
Therefore, instead of including the data in-line in a series of "if greater than X and if less than Y" statements, it would be far more efficient to have the script call another program that loads the geoIP list into an array if it is not already loaded, and then returns a pointer to the array whenever it is called. This loader/array-pointer program should then continue to run, listening for further requests from additional instances of the calling script. The calling script could then take the array pointer and index through the array doing the greater-than/less-than compares in a "while" construct, until it finds a matching range or reaches the end of the array.
The advantage here is that IP addresses are in a table, loaded into an array in memory, rather than hard-coded into your script. This way, when the geoIP data changes once a week, you do not need to re-write your code. All you need to do is to restart the geoIP array loader script to re-load the array from your newly uploaded geoIP file. (These files are available in easy-to-use .csv format: plain text, comma-delimited list.)
Now that I've described this in general, I'll have to refer you to the PERL scripting forum for help implementing this, as it is based on general "efficient-computer-programming" knowledge, and I have never coded this application in PERL myself. :)
Also, you might look into a more user-friendly error message: For human-readable "page" requests, such as those for html or php pages, output a message that tells the visitor that your site is specific to France. Otherwise, they will assume that something is wrong with the site, or with their browser or ISP, etc., and may keep trying to access the site. This defeats your purpose. You might even consider providing a redirect or a link and a meta-refresh to a similar US-focused site... You might even find a site willing to reward you for the traffic your refer... ;)
[added] Actually, the always-running PERL script could accept an IP address from the calling script, and then just return an "allowed" or "not allowed" answer to the calling script. That's even simpler. [/added]
Jim
[edited by: jdMorgan at 3:43 pm (utc) on April 29, 2007]
Some 3-5 years ago and before any types of sorted lists were available, I implemented and a separation of Oceanic ranges from the APNIC ranges, in order to allow access for Oceanic visitors.
The solution remains in effect today, thanks to Jim.
One beginning may be in referrals?
Perhaps you could implement referrals that only come from websites that offer the ".fr" at beginning or end of the domain name.
There are multiple tools with accumulated lists of IP ranges.
One tool is:
http ://www.irnis.net/soft/xipl/
or
http ://www.sharewareconnection.com/titles/ip-country.htm
A google search will eventually lead you to a source:
[google.com...]