1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Mobile desktop geo targeted redirect script

Discussion in 'General Scripting Chat' started by elviswong, Feb 14, 2014.

  1. elviswong

    elviswong Senior Member Premium Member

    Joined:
    Nov 8, 2011
    Messages:
    918
    Likes Received:
    240
    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
     
  2. solventnine

    solventnine Junior Member

    Joined:
    Dec 4, 2009
    Messages:
    113
    Likes Received:
    16
    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).
     
  3. IamNRE

    IamNRE Jr. VIP Jr. VIP Premium Member

    Joined:
    Aug 18, 2010
    Messages:
    4,663
    Likes Received:
    7,108
    Occupation:
    Generate Leads With FB Ads For Just $1
    Home Page: