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.

publicIP Address54.161.106.81
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 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 GPS)
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.
detect.screenWidth();

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

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

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

// Get latitude from GPS & update html conent of ID element passed.
// Null, if GPS unavailable.
detect.latitude("latitude");

// Get longitude from GPS & update html conent of ID element passed.
// Null, if GPS unavailable.
detect.longitude("longitude");

// Get address from GPS & update html conent of ID element passed.
// Null, if GPS unavailable.
detect.address("address");