Detect if User Lives in the Continuous United States with PHP


I’ve been searching Google to see how I could detect if someone living outside of the US. I would like to not display certain html if the website viewer lives outside the US. Specifically the contiguous US if that is possible.

I found something like this that might work but there might be an easier way:

 * ip__allocation.php
    if (isset($_SERVER['REMOTE_ADDR']))
        include 'ip_in_range.php';
        $IPAllocation = array(
            foreach ($IPAllocation as $addressRange) {
                if (ip_in_range($clientIP, $addressRange))


Go grab the free versions of any of the GeoIP rendering services state CSV, such as MaxMind’s.

My suggestion then is to load this data into a database (which should be fairly easy), and then simply ip2long the IP address, and use it for a BETWEEN check. That way the database handles all of the looping/indexing that needs to be done (as this can be a rather large amount of data!) and returns only the result you’re interested in (which should be either 1 row or none)

Thanks. It’s just a simple thing I’m wanting to do. I have free shipping but only to US customers and if the customers order is greater than then it displays “You get free shipping”. I just want to not show this at all to anyone out side of the US. Creating a whole database and another account and everything for this one thing might be a little overkill but it sounds like it would work thou.