#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2005
    Posts
    11
    Rep Power
    0

    Question Redirect from specific page to mobile page


    My client has created a QR Code that goes to a specific page on a non-mobile site. The client does have a mobile site, m.customersdomain.com

    Question is, the QR Code has already been submitted to print for advertising and is going to a regular URL.

    Is there a way to look for mobile devices that hit this one non-mobile page and redirect them to a specific mobile URL / page?
  2. #2
  3. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Location
    Oxford, United Kingdom
    Posts
    40
    Rep Power
    3
    That's easily possible.

    Server-side:
    Get a list of all common mobile browser user-agents.

    Store them somewhere. In a DB, JSON file, or just as an array..
    Check each visitor's user-agent to see if it exists in your list of mobile user-agents. If it does, do the redirect.

    Client side:
    Check the screen resolution. If it's lower than the standard (lowest) desktop/laptop screen size, or if it's mobile size, do the redirect (in JS).
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2005
    Posts
    11
    Rep Power
    0
    NavNav,

    Have this so far for JS:

    if ((screen.width <= 700) &&
    currentpage("http://customersite.com/gotopage")) {
    window.location = "http://m.customersite.com/gotopage";
    }

    I just need to figure out how to look @ the current URL, and if it is in fact http://customersite.com/gotopage, then send them via window.location to http://m.customersite.com/gotopage
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2005
    Posts
    11
    Rep Power
    0

    Question


    NavNav,

    This may do it:

    if ((screen.width <= 700) &&
    location.href("regularURL")) {
    window.location = "mobileurl";
    }

    ...maybe???

    Any better way?

    Thanks!
  8. #5
  9. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Location
    Oxford, United Kingdom
    Posts
    40
    Rep Power
    3
    You shouldn't need to check the current URL unless you've got that code running on both sites. If so, that's a problem. Only have that code on the non-mobile site. That way, you won't need to check the current URL.
  10. #6
  11. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2005
    Posts
    11
    Rep Power
    0
    Hi NavNav,

    Correct...this would only be on the regular site...not going to do on mobile site.
  12. #7
  13. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Location
    Oxford, United Kingdom
    Posts
    40
    Rep Power
    3
    So you wont need to check the current URL, then xD
  14. #8
  15. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Location
    Oxford, United Kingdom
    Posts
    40
    Rep Power
    3
    You should also check this out:
    http://stackoverflow.com/questions/3...vice-in-jquery

    The code provided in that answer should help allot.
  16. #9
  17. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2005
    Posts
    11
    Rep Power
    0
    Current regular site has 5 pages lets say.

    I would redirect the user away from regular page4 b/c of what this particular QR Code URL is...and send them to the mobile version of page4.

    Wouldn't I need to have a global javascript block saying:
    If this is a mobile device and they're trying to hit page 4, the redirect them to the mobile site version of page 4.

    Correct?
  18. #10
  19. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Location
    Oxford, United Kingdom
    Posts
    40
    Rep Power
    3
    Ah, right, it's best if you do that through server-side, then:

    PHP Code:
    function mobileRedirect()
    {
        
    $mobilePlatforms = array
        (
            
    'Android',
            
    'webOS',
            
    'iPhone',
            
    'iPad',
            
    'iPod',
            
    'BlackBerry'
        
    );
        
        
    $pages = array
        (
            
    'www.blahblah.com/page1' => 'www.m.blahblah.com/page1.php',
            
    'www.blahblah.com/page2' => 'www.m.blahblah.com/page2.php',
            
    'www.blahblah.com/page3' => 'www.m.blahblah.com/page3.php',
            
    'www.blahblah.com/page4' => 'www.m.blahblah.com/page4.php',
            
    'www.blahblah.com/page5' => 'www.m.blahblah.com/page5.php',
        );
        
        
    $currentPage $_SERVER['SCRIPT_NAME'];
        
        
    $userAgent $_SERVER['HTTP_USER_AGENT'];
        foreach( 
    $mobilePlatforms as $platform )
        {
            if ( 
    stripos$userAgent $platform ) !== false )
            {
                
    //by default, we'll send them to the mobile homepage
                
    $location 'www.m.blahblah.com';
                
                
    //but we then check if they're on a page that we want a custom redirect for
                
    if ( empty( $pages$currentPage ] ) === false )
                {
                    
    $location $pages$currentPage ];
                }

                
    header'Location: ' $location );
                break;
            }
        }

    Make sure you change the $pages array to contain the relevant elements and keys.
    Last edited by navnav; April 13th, 2013 at 01:14 PM.
  20. #11
  21. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2005
    Posts
    11
    Rep Power
    0

    Thumbs up


    Thanks tons NavNav...should be able to test this by tonight or tomorrow...will let you know for sure.

IMN logo majestic logo threadwatch logo seochat tools logo