PHP:
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.
http://demo.mobiledetect.net/
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:
JAVASCRIPT:
Using Javascript programming language, there are several alternatives that vary in complexity.
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:
Source: https://coderwall.com/p/i817wa/one-line-function-to-detect-mobile-devices-with-javascript
2. - Javascript also provides an alternative consisting of verifying whether the following attributes return true:
/Android|webOS|iPhone|iPad|iPod|BlackBerry/i.test(navigator.userAgent)
Once again, with the help of JQuery, we can add the corresponding script to the head