Part of development that is fun yet tricky is developing for a global audience. For dcshoes.com, we are having 1 single site address (www.dcshoes.com) that will act differently according to the location of the user (and language too, but I wont get into that).
At some point in time, a developer must deploy some code that will
1. Detect the users IP Address
2. Based on an IP table or related, determine the users current country
Now generally speaking, when you have a function of this nature, it will take in an IP and spit back out a 2 or 3 letter ISO country code.
During times when you want to “see how your site looks like from someone else”, usually you will put in a flag such as “?override_country=DE” if say, you want to be in Germany. This is not a bad approach.
However for me, I like to actually a) test the Geo IP Detection is working and b) see if the appropriate action for the appropriate country is taking place
Below you will see a very dumbed down script of what I”m talking about. Anyhoo, I think it could be helpful to some people if they need to spoof their IP and tell their code they have a different IP rather than having it detect theirs all the time.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
if($_GET['user_override'] == 'yes'){ $ip = "80.69.48.0"; //azerbaijan //$ip = "117.53.173.85"; // australian ip //$ip = "173.203.164.216"; // brazil //$ip = "78.138.5.104"; //botswana //$ip = "12.130.81.96"; //canada //$ip = "64.117.130.144"; //chile //$ip = "201.244.61.46"; //columbia //$ip = "31.201.155.0"; //france //$ip = "64.64.4.138"; //french guiana //$ip = "83.229.15.144"; //gabon //$ip = "80.153.148.252"; //germany //$ip = "46.183.16.0"; //greece //$ip = "31.11.32.0"; //italy //$ip = "14.137.224.0"; // japan //$ip = "63.250.179.112"; //mexico //$ip = "58.84.224.0"; // new zealand //$ip = "46.105.145.188"; //portugal //$ip = "46.19.224.192"; //serbia //$ip = "46.28.208.0"; //spain //$ip = "31.201.132.0"; //sweden //$ip = "202.72.104.0"; // timor-leste //$ip = "62.146.34.96"; //UAE //$ip = "67.52.123.30"; //united states //$ip = "46.136.34.0"; //vatican } else{ $ip = getRealIpAddr(); } |
If you look at the code above, you will see it is super basic. What it is doing is:
1. Check to see if there is a GET variable named ‘user_override’ and if the value of that is ‘yes’
– TRUE – If it is set to use, then use one of the IP addresses below. In our case, we are pretending to act like we are in Azerbaijan
– FALSE – If there is no “user_override” or if it is set to anything other than use, get the location based on the users IP (so if you’re in US, you’ll have a US IP)
The above IPs DO work and I have tested them with MaxMind GeoIP Detection. I will add to the list as I add to my own list.
Enjoy.