How do I detect mobile clients on my web server?

26,455

Solution 1

You can grab the User Agent. That tells what browser type it is (iphone, chrome, ie, anything)

To help you:

http://whatsmyuseragent.com/

http://en.wikipedia.org/wiki/User_agent

Solution 2

You need to check the header of the HTTP request. You can find both the OS and the browser being used in the "User-Agent" field.

If you are using javascript then use the navigator object

navigator.userAgent

If you are using php then you can access the HTTP header

$userAgent = $_SERVER["HTTP_USER_AGENT"];
Share:
26,455
shebelaw
Author by

shebelaw

Updated on July 09, 2022

Comments

  • shebelaw
    shebelaw almost 2 years

    When http request comes to my server, how do I detect if it is from iphone, android, or other devices?

  • ceejayoz
    ceejayoz about 13 years
    Do note that this is easily faked.
  • Pepe
    Pepe about 13 years
    @ceejayoz Yes of course. But I don't see any issues arising from that since the users would prob want the best experience and layout that fits the actual client being used. So they don't really have any interest in doing that.
  • Pepe
    Pepe about 13 years
    @ceejayoz Also I don't think the OP can do anything to prevent that on his end...
  • ceejayoz
    ceejayoz about 13 years
    Agreed. Just worth noting, as I've seen people try to restrict access in this manner and be surprised that it won't work for determined users.
  • shebelaw
    shebelaw about 13 years
    In the case of iPhone can I also get ESN, IME ID of the phone using JavaScript?
  • Pepe
    Pepe about 13 years
    @user736659 I don't think so.
  • Shadow The Kid Wizard
    Shadow The Kid Wizard over 11 years
    @JJPA true, offender is now suspended and the illegal answers deleted.
  • Shadow The Kid Wizard
    Shadow The Kid Wizard over 11 years
    @JJPA not my doing, just reporting it to prevent the author here from getting confused when the link you posted does not give him the answer you meant to show..