Forum Moderators: coopster

Message Too Old, No Replies

Finding non-US IP addresses in PHP

         

csdude55

1:46 am on Apr 1, 2017 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I'm trying to prevent non-US IP addresses from creating an account. They can view the site all they want, they just can't do anything unless I whitelist them.

In Perl, I was using:

use Net::Whois::IP qw(whoisip_query);

my $response = whoisip_query($ENV{'REMOTE_ADDR'});

$orgname = $response->{'OrgName'};
if (!$orgname) { $orgname = $response->{'NetName'}; }

if ($orgname =~ /asia|africa|latin|singlehop|ripe/i) {
$foreign = 1;
}


That wasn't quite perfect, but it worked OK.

Now I'm rebuilding the script in PHP, but I can't figure out how to fetch "OrgName" or "NetName". I found gethostbyaddr(), but that doesn't give me what I need.

I found this overly-complicated script from 5 years ago:

[binarytides.com...]

Is there a better / faster / easier way to get the info I need? Or, more accurately, to find whether the user is not within the US? My backup is to block by a list of "known" non-US IP addresses, but I'm not sure how reliable that really is.

phranque

3:36 am on Apr 1, 2017 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



perhaps Net_Geo, Net_GeoIP or Net_Whois will work:
https://pear.php.net/manual/en/package.networking.php [pear.php.net]