Rohan Shewale's Blog

Check There - A Simple Experiment


Check There – is a simple experiment which makes use of Request-Headers to determine the client device. Few months ago I has visited @davidprati’s pleasevisit experience, was inspired by that mischievous experiment, and today got free time and sudden urge to recreate it.

The back-end written in PHP as a simple single function, which compares the HTTP_USER_AGENT of $_SERVER global variable with with regex of common/popular user-agent names found in mobile devices, and return the result in boolean value, which is check with (my favorite) ternary operator to place the classes & text where required.

Here is the snippit of the function —

function isMobile() {
    return preg_match("/(android|avantgo|blackberry|bolt|boost|cricket|docomo|fone|hiptop|mini|mobi|palm|phone|pie|tablet|up\.browser|up\.link|webos|wos)/i", $_SERVER["HTTP_USER_AGENT"]);
}

This works for this small experiment, I would suggest something like this popular Mobile-Detect library in production. Though it’s a better option to design a mobile first website rather than a dedicate mobile one (unless its required too!), also Request-Headers can easily be faked since there are coming form client-side.

Live Preview link : Check There


Article Publish Date: June 01, 2016