Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I detect mobile clients on my web server?

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

like image 515
shebelaw Avatar asked May 12 '11 17:05

shebelaw


People also ask

How do websites detect mobile devices?

It works by examining information contained in the HTTP headers, particularly User Agent strings sent by all web-enabled devices. The User Agent is looked up in a database that returns any requested information including device type.

What is the best way to detect a mobile device?

In summary, we recommend looking for the string “Mobi” anywhere in the User Agent to detect a mobile device. Like this: if (/Mobi/. test(navigator.

How do you identify a client device?

The User-Agent header contains a line of text that can be used to identify a user agent and client device. Most of the time, we can find the device model and manufacturer from the User-Agent header. It may also contain information such as the client device's OS version, browser version, Java capabilities, etc.

How do I know my request is coming from mobile or PC?

you can use below code, var index = navigator. appVersion. indexOf("Mobile");


2 Answers

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"];
like image 122
Pepe Avatar answered Sep 26 '22 20:09

Pepe


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

like image 26
JD Audi Avatar answered Sep 25 '22 20:09

JD Audi