1

I am a Canadian Company. I have my main website with all products in US$ but then using this redirect, any traffic from Canada is redirecting to a my other mirrored website where all of the products are priced in CND$.

This is the script I am using in the HEAD of my pages of the US site with Maxmind GeoIP Lite. It works perfectly.

<script language="JavaScript" src="http://j.maxmind.com/app/country.js" type="text/javascript"></script>

<script language="JavaScript" type="text/javascript">// <![CDATA[
if(geoip_country_code() == "CA"){
    document.write("");
    window.location = 'http://www.myCanadaianWebsite.com';
}
// ]]></script>

The only problem or annoying thing is that i have a hard time checking and testing the US site out myself since I am located in Canada. I am having to delete the script from my US webpage every time i want to check my US site. Then I re-paste it back in when i am done looking.

Is there a way that I can add an exception to my script that will not redirect me based on my IP or location? I have googled it and haven't come across anything like that. Would love to find a solution to this problem. Thanks.

3 Answers3

0

You can either use server side code to selectively output the script depending on the IP, or you can use a tool like Charles Proxy to substitute your own script for http://j.maxmind.com/app/country.js that has hard coded "This is the US" data in it.

Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335
0

In php, you can use $_SERVER['REMOTE_ADDR'] to get your IP. To get the remote IP in javascript, see How to get client's IP address using javascript only?

I would suggest instead the following solution: Install a script which allows you to set or unset a cookie: see here for docs: http://www.markusnordhaus.de/2012/01/20/using-cookies-in-javascript-part-1/

Community
  • 1
  • 1
Adder
  • 5,708
  • 1
  • 28
  • 56
0

I might move the checking over to the server side, but failing that give yourself a cookie (jQuery based example).

if(geoip_country_code() == "CA" && $.cookie('pretendimamerican') === null) { 
  //Redirect
}

Then just give yourself that cookie, or make a secret URL that will set it for you. This way you can use it regardless of your IP, and send it to colleagues easily. Clearly your implementation isn't a security thing, but a price presentation thing, so I'm not concerned about people faking it (since those people could just as easily disable what you've got now).


On a related note, if your testing gets more advanced, I started a company to help people test their GeoIP application with proxies: https://wonderproxy.com/

preinheimer
  • 3,712
  • 20
  • 34