PHP: Check whether website is called from iPhone, iPad or Android smartphone
Question by Guest | 2012-09-17 at 02:51
I would like to check with PHP, if my site is called from an iPhone, iPad or Android phone. Is there already any PHP function for that or how do I do this?
Related Topics
Android Splash Screen Tutorial
Tutorial | 0 Comments
Android Table Layout with columns of equal width
Tutorial | 0 Comments
Android Getting Sound Levels
Open Question | 1 Answer
PHP: Check Strings with Ctype-Functions for Character Classes
Article | 0 Comments
Android SDK Manager: Problem with installing packages "File not Found (Access is denied) Done. Nothing was installed"
Question | 4 Answers
HTML Form: Redirection depending on Radiobutton or Checkbox State
Tutorial | 0 Comments
Important Note
Please note: The contributions published on askingbox.com are contributions of users and should not substitute professional advice. They are not verified by independents and do not necessarily reflect the opinion of askingbox.com. Learn more.
Participate
Ask your own question or write your own article on askingbox.com. That’s how it’s done.
As far as I know, there is still no separate PHP function doing this. Maybe it will be implemented, when smartphones are even more popular. Until then, I would say, you have to do it for yourself:
We simply look, whether the user agent contains one of the words "Android", "iPad" or "iPhone". In the boolean variables of the same name, we write the result, true or false.
Now, it is easy to determine the device with which the visitors is calling the website:
However, you have to note, that you can easily fake your user agent, you cannot rely on that information. For example, you can use Firefox add-ons to fake being a smartphone, although you are accessing a website from your laptop or desktop PC. But since you probably only want to display a different content and it does not depend on the world and most users will even not distort their User Agent, the function should be totally fine for your purpose.
2012-09-17 at 16:59