Forum Moderators: coopster

Message Too Old, No Replies

Ban Countries by IP

Can this be done via PHP?

         

neophyte

4:38 am on Feb 18, 2006 (gmt 0)

10+ Year Member



Hello All -

I've got a client who wants to ban the viewing of his site by users in the Philippines due to high piracy rates there. I've seen other sites that do this regarding various countries, but of course they don't say how they do it.

Is there a PHP script (or way to write one) that captures and compares a users IP address against a database of country based IPs?

Also, if I'm coming from an IP of 000.00.00.000 which part of this string defines the country? Or is it a numeric combination of these numbers which determine the users country of origin?

I've googled "ban country by IP" which gives me some third-party sofware to buy that will do this, but is it easy enough to do myself?

Appreciate all help/advise in advance.

Neophyte

Jaunty Edward

4:55 am on Feb 18, 2006 (gmt 0)

10+ Year Member



Hi neophyte,

if you know a little bit of PHP I hope you will understand this.

// the code will store the IP of the visitor in the variable $ip

$ip = $_SERVER["REMOTE_ADDR"];

you will require a DB that has all the IP recorded with the country names. one paid solution is at ip2location.com

just take out the value of the IPs from the DB for that country and then compare it with $ip.

I am sure someone will be able to make better comments on the issue. I don't know of any free site that gives the free DB of IPs and countries.

Thanks,
Jaunty

DrDoc

4:56 am on Feb 18, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



There are a couple tools out there where you can download an IP-Country database.

[ip-to-country.webhosting.info...] is completely free.

jatar_k

5:41 pm on Feb 18, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



I've used the one DrDoc linked to many times, works well. They have example scripts and all sorts.

If you any issues with it I can probably help.

neophyte

12:51 am on Feb 27, 2006 (gmt 0)

10+ Year Member



Thanks to all...and sorry for the late, late reply.

I suddenly got side-tracked to another project but will checkout all suggestions and reply back if I have any additional problems or questions.

Everyone's help is, as always, greatly appreciated.

Neophyte

inveni0

3:48 pm on Feb 27, 2006 (gmt 0)

10+ Year Member



It seems to me that those into 'Pirating' could (and probably do) spoof their IPs......Perhaps there is another line of defense?

jatar_k

6:31 pm on Feb 27, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



there isn't much spoofing really, mostly just people using proxies.

remember the key is to make things difficult. This is one step. Along the way you can also cross check any information they enter into a form with the country they say they are in.

there is no fix all but you can reduce it quite a bit.