Results 1 to 6 of 6
  1. #1
    Join Date
    Mar 2007
    Posts
    284

    How can I redirect all traffic which is NOT on a mobile device?

    Hey WHT!

    I have another question.

    I've finally got a mobile website working, and I tested it on my phone and it works fine. It's for some forums, so it's fairly complicated. So, I'm just stuck on one last thing!

    Basically, members can load the site, login, navigate around and post, etc.. And it changes their skin to the "Mobile Skin" when they login from the mobile login page. But the problem is that if they login later on their computer, then they're still in the mobile skin!

    So, I need to find a way to redirect all traffic which is not using a mobile browser to the default skin. This would also prevent people using the skin just to hide all my ads or something.


    I was thinking of tricky ways to get this done, but I don't know the code for any of it.. sadly. Would it be possible to redirect a user based on their screen resolution, browser type or User Agent for mobile users? It needs to redirect users who are NOT on their mobile device.. Haha.

    Thanks,
    ~Chris`

  2. put all your pages through php parser using addtype, and check the user agent and redirect accordingly
    www.phporaclehosting.com - cheap oracle and php hosting - specialist in php and oracle hosting. from £2.99 a month

  3. #3
    Join Date
    Jan 2006
    Location
    Athens, Greece
    Posts
    1,481
    Take this list
    http://en.wikipedia.org/wiki/List_of..._mobile_phones
    and using the $_SERVER['HTTP_USER_AGENT'] you can redirect properly. Example for blackberry:
    PHP Code:
    if ((strpos($_SERVER['HTTP_USER_AGENT'], 'BlackBerry')) !== false)
    {
        
    // set moblie skin

    Well regex would be better here, but that's a start.

  4. #4
    Join Date
    Aug 2002
    Location
    Superior, CO, USA
    Posts
    635
    Use the WURFL library. Depending on your implementation language there are many different ways to access the library.

    Take a look at the WURFL homepage for more information.

  5. #5
    WURFL, as suggested, or you can probably also check the accept header to see if it includes wml or not. If it includes wml it's probably (but not 100% guaranteed) mobile. If it doesn't include wml, it's probably not a mobile device.

  6. #6
    Join Date
    Aug 2005
    Location
    UK
    Posts
    654
    Quote Originally Posted by Steve_Arm View Post
    Take this list
    http://en.wikipedia.org/wiki/List_of..._mobile_phones
    and using the $_SERVER['HTTP_USER_AGENT'] you can redirect properly. Example for blackberry:
    PHP Code:
    if ((strpos($_SERVER['HTTP_USER_AGENT'], 'BlackBerry')) !== false)
    {
        
    // set moblie skin

    Well regex would be better here, but that's a start.
    Building on what Steve suggested, you can accomplish the same in a mod_rewrite rule set, example:
    Code:
    RewriteCond  %{HTTP_USER_AGENT}  BlackBerry|NetFront|SymbianOS|MIDP|WAP2|etc...
    RewriteRule  ^/$                 /homepage.max.html
    Based on this you could even direct phones with lesser WAP or XHTML support some where else.

    What I use is sightly different, though more complex. Most mobile devices send a link to their 'UAProf' (User Agent Profile). This is an XML file that documents the capabilities of the device.

    Wikipedia page on UAProf

    Example XML file from one of my phones (SE K770i)

    If I haven't already got the relevent file/db record cached the site downloads the XML and queries it for the relevent stats then stores them in a more convenient format (MySQL db) and discards the XML (lots of info I don't need).

    I use the screen size and supported video codecs to know what to send the phone/handset.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •