How to detect mobile visitor

Discussion in 'Programming' started by themlife, Jan 26, 2008.

  1. #1
    Hi everyone,

    I've had a mobile version of my site for some time but it's only good for people who know the mobile link.

    I've seen some sites that will redirect a visitor when it detects that they are browsing from a mobile device/browser.

    Does anyone know how these sites do it? Anyone have a code snippet or link they can share with me?

    I appreciate any help. Thanks!!
     
    themlife, Jan 26, 2008 IP
  2. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #2
    nico_swd, Jan 26, 2008 IP
    themlife likes this.
  3. themlife

    themlife Peon

    Messages:
    105
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thanks nico! PHP is what I wanted. This looks perfect.
     
    themlife, Jan 26, 2008 IP
  4. daringtakers

    daringtakers Well-Known Member

    Messages:
    808
    Likes Received:
    23
    Best Answers:
    0
    Trophy Points:
    110
    #4
    You might get it from 'user agent' header of the request
     
    daringtakers, Jan 27, 2008 IP
  5. awatson

    awatson Active Member

    Messages:
    112
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    53
    #5
    Never tried it, but seems to me looking at the client screen size might be a clue that it's a mobile device.
     
    awatson, Jan 28, 2008 IP
  6. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #6
    That would require Javascript, and a lot of mobile devices don't support Javascript. Plus it can usually be disabled.
     
    nico_swd, Jan 28, 2008 IP
  7. isTay

    isTay Peon

    Messages:
    55
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    If I remember correctly PHP has a regex for getting the user agent, all you would have to do is use the data retrieved to redirect them.
     
    isTay, Jan 28, 2008 IP