Easy to use PHP & JS classes to allow a website to easily detect useful information about the client.

The 'Detect' PHP class expands the open-source Mobile Detect class from mobiledetect.net, plus added functions to increase the detected information.

The 'detect' JS class features functions unable to be used within PHP as the information can only be retrieved from the client.

Your device:

publicIP Address54.92.201.232
languageHost Nameec2-54-92-201-232.compute-1.amazonaws.com
businessOrganisationAS14618 Amazon.com, Inc.
settings_overscanScreen Size
aspect_ratioViewport Size
computerDevice TypeComputer
Operating SystemUnknown OS
BrowserUnknown Browser
navigationLocationUS

PHP Class

Simply include or require the class file & use. No need to instantiate the class as all methods are static:

// Include or require the Mobile_Detect.php file from mobiledetect.net
require_once 'path_to/Mobile_Detect.php';

// Include or require the class file
require_once 'path_to/detect.php';

// Any mobile device (phones or tablets)
if (Detect::isMobile()) {

}

// Gets the device type ('Computer', 'Phone' or 'Tablet')
echo Detect::deviceType();

// Any phone device
if (Detect::isPhone()) {

}

// Any tablet device
if (Detect::isTablet()) {

}

// Any computer device (desktops or laptops)
if (Detect::isComputer()) {

}

// Get the IP address of the device
echo Detect::ip();

// Get the ID address host name of the device
echo Detect::ipHostname();

// Get the IP address organisation of the device
echo Detect::ipOrg();

// Get the country the IP address is in (IP address location inaccurate)
// (JS function available which uses the Geolocation API)
echo Detect::ipCountry();

// Get the name & version of operating system
echo Detect::os();

// Get the name & version of browser
echo Detect::browser();

// Get the brand of device (only works with mobile devices otherwise return null)
echo Detect::brand();

// Check for a specific platform with the help of the magic methods:
if (Detect::isiOS()) {

}

if (Detect::isAndroidOS()) {

}

All methods within the Mobile Detect class from mobiledetect.net are static & available.

Detect::method();

JS Class

Include the JS file:

<head>
    ...
    <script type="text/javascript" src="path_to/detect.js"></script>
    ...
</head>

Only methods which require direct access to the local client to get information are available in JavaScript:

// Get screen width in pixels
var myVar = detect.screenWidth();

// Get screen height in pixels
var myVar = detect.screenHeight();

// Get viewport (browser window minus any toolbars etc) width in pixels
var myVar = detect.viewportWidth();

// Get viewport (browser window minus any toolbars etc) height in pixels
var myVar = detect.viewportHeight();

// Get latitude from Geolocation API (GPS)
// Give 'idOfElement' to update the innerHTML of, if Geolocation API is unavailable or errors it will update with error message
detect.latitude('idOfElement');

// Get longitude from Geolocation API (GPS)
// Give 'idOfElement' to update the innerHTML of, if Geolocation API is unavailable or errors it will update with error message
detect.longitude('idOfElement');

// Get address from Geolocation API (GPS)
// Give 'idOfElement' to update the innerHTML of, if Geolocation API is unavailable or errors it will update with error message
detect.address('idOfElement');

Download

Please note the following:

  • The 'Mobile_Detect.php' file from mobiledetect.net has not been included in the zip file. You can download it and update the 3rd party file at your convenience.
  • As of Chrome 50, the Geolocation API will only work on secure contexts such as HTTPS. If your site is hosted on a non-secure origin (such as HTTP) the requests to get the users location will no longer function (Source).
  • On devices & browsers which support the Geolocation API, the user is notified that the website would like to know the location of the device. The user must confirm this is ok for the Geolocation API to work.

Download Version 1.0.4

You are under no obligation, however if you'd like to donate to me, I'd really appreciate your contributions towards my hosting & time developing this.

PayPal.Me