Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I determine whether it's a mobile device with PHP?

Tags:

php

mobile

I am writing a website with PHP. Since it will need to be accessed by anyone on the network to access the internet I have to create a mobile version. How do I best check if it's a mobile device? I don't want to have a switch statement with 50 devices at the end since I don't only want to support the iPhone.

Is there a PHP class I could use?

like image 296
Thomaschaaf Avatar asked Dec 22 '08 11:12

Thomaschaaf


People also ask

How does Website detect mobile?

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 PHP in mobile?

January 29, 2016 September 17, 2018 Vernit Gupta Mobile. PHP or Hypertext Preproccessor is one of the most robust and dynamic programming languages in the technology space offering ample scope for developers to tweak the source code as per their own specifications.


1 Answers

You need to check several headers that the client sends, such as USER_AGENT and HTTP_ACCEPT. Check out this article for a comprehensive detection script for mobile user-agents in PHP.

like image 78
Eran Galperin Avatar answered Nov 01 '22 19:11

Eran Galperin