Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Might it be possible to block an entire US state from accessing my site, using PHP?

Tags:

javascript

php

ip

I have a client that would like to block an entire US state from accessing his site. He is OK with the idea of it not being perfect. Is this possible?

I found this service: http://www.maxmind.com/en/home

like image 325
user1040259 Avatar asked Jan 15 '23 15:01

user1040259


2 Answers

Not with any sort of good accuracy. Geolocation via IP can be helpful for a general idea, but it's often incorrect, especially with larger ISPs that have a national or regional footprint.

I live in NYS, but my phone shows up as Kansas, and some ISPs in the area show up from Texas.

like image 126
ceejayoz Avatar answered Jan 30 '23 03:01

ceejayoz


PHP-Ip-Block uses Maxmind service you mentioned.

You need to change following lines in index.php; (lines that sould be changed)

$okc = array('Canada', 'United States'); //array of countries you want to let in

// Decide what to do with your country arrays
if (in_array($userco,$okc))
  echo " "; //allowed in 
else
 header( 'Location: http://www.google.com/' );//this is where to send countries not matched.

to this; (new lines)

$okc = array('United States'); //array of countries you want to NOT let in

// Decide what to do with your country arrays
if (!in_array($userco,$okc))
  echo " "; //allowed in 
else
 header( 'Location: http://www.google.com/' );//this is where to send countries matched.
like image 40
Turcia Avatar answered Jan 30 '23 03:01

Turcia