Mobile desktop geo targeted redirect script

elviswong

Senior Member
Joined
Nov 8, 2011
Messages
983
Reaction score
276
Guys
i'm looking a for a redirect script.

Surfer arrives at mysite.com (main url), script detects if he's using his PC or Laptop, forwards them accordingly, which then uses a geo-targeted filter to finally send him to the right url

So if a guy from Usa passes by my site and he's using a PC, I would server him:
mysite.com/pc/usa.php

Canadian guy with an Iphone ? Then it would be:
mysite.com/mobile/iphone.php

etc...

Do you know where i could get my hands on this ?
Thanks
 
You can do both relatively easily.

For the geo-targeting, use MaxMind. If you don't want to pay for it, they offer a free GeoIP database.

There are tons of implementations of the GeoIP database in multiple languages (since all you'll need is country, you could use the free database?it's only countries). You'll use the user's IP to get the country, then redirect accordingly. Something like:

Code:
// pseudocode //

     $country = GeoIPCountry($users_ip_address)
     
     $redirect = http://mysite.com/$country

     RedirectTo($redirect)


And here's a working sample of the Desktop/Mobile:
Code:
<script type="text/javascript">// <![CDATA[
    var mobile = (/iphone|ipod|android|blackberry|mini|windows\sce|palm/i.test(navigator.userAgent.toLowerCase()));
    if (mobile) {
        document.location = "MY_MOBILE_PAGE";
    }
// ]]></script>

You'd be better off using a responsive-design framework like Bootstrap and letting that handle the mobile/desktop view. This is especially true with your desire to redirect both on format and geo-location. Of course you can adapt that JavaScript to set a mobile/desktop flag, utilize AJAX to retrieve the country from your scripting language, and send accordingly. If you wanted to do that, you'd have your "RedirectTo()" function print the country out instead of redirecting (you'd want to rename that function, too).
 
Back
Top