Using PHP programming language, the easiest and most reliable way of recognizing a device is using the Mobile_Detect class, found at the following URL: http://mobiledetect.net/.
Mobile Detect recognizes the device (including tablets). Use the text chain User_agent combined with the HTTP header to detect the environment it is navigating in.
It has a test URL where we can see the result generated by the code. We can also observe the methods that can be implemented.
In the case of loading a script within the html page, and taking into account whether or not the device is a cell phone, we could use the following example:
1. - The simplest way is using the following function:
The function tests if window.orientation exists, since only mobile devices return true in this case.
Using JQuery, we could load the script as follows:
Once again, with the help of JQuery, we can add the corresponding script to the head