How to find out if a website is open on a mobile or PC

We have a website developed in PHP. It works great. We used jQuery for all situations, such as slide shows, menus, etc.

This site contains a large number of large image sizes. because of this, when viewing on a mobile phone, the user has to scroll a lot.

How can we find out if a client (browser) is trying to access our site, a mobile phone or a standard PC.

Is there a standard way to create a site for such situations?

TIA

+4
source share
4 answers

You should look at Tera-WURFL , a software package based on PHP and MySQL that detects mobile devices and their capabilities. Here is the Tera-WURFL code that you would use to determine if a request is coming from a mobile device:

<?php require_once("TeraWurfl.php"); $wurflObj = new TeraWurfl(); $wurflObj->GetDeviceCapabilitiesFromAgent(); if($wurflObj->capabilities['product_info']['is_wireless_device']){ echo "This is a mobile device"; }else{ echo "This is a desktop browser"; } ?> 
+5
source

you should check the header of the user agent that is sent by the HTTP request. Since there are so many user attacks, it is really difficult to recognize different devices / platforms. There is a free library for this that can help: wurfl

It basically maps the user agent to a device object that you can query for it. So in your layout you can use screen width / height, which image formats are supported, etc.

+5
source

We sometimes use Apache rewrite rules when a client wants to redirect traffic before it reaches our server.

See http://www.bemoko.com//training.team/help/team/pc-to-mobile-redirect for more details.

+1
source

Source: https://habr.com/ru/post/1306558/


All Articles