* @license MIT License https://github.com/serbanghita/Mobile-Detect/blob/master/LICENSE.txt * */ // This is mandatory if you're using sessions. session_start(); // It's mandatory to include the library. require_once '../Mobile_Detect.php'; /** * Begin helper functions. */ // Your default site layouts. // Update this array if you have fewer layout types. function layoutTypes() { return array('classic', 'mobile', 'tablet'); } function initLayoutType() { // Safety check. if (!class_exists('Mobile_Detect')) { return 'classic'; } $detect = new Mobile_Detect; $isMobile = $detect->isMobile(); $isTablet = $detect->isTablet(); $layoutTypes = layoutTypes(); // Set the layout type. if ( isset($_GET['layoutType']) ) { $layoutType = $_GET['layoutType']; } else { if (empty($_SESSION['layoutType'])) { $layoutType = ($isMobile ? ($isTablet ? 'tablet' : 'mobile') : 'classic'); } else { $layoutType = $_SESSION['layoutType']; } } // Fallback. If everything fails choose classic layout. if ( !in_array($layoutType, $layoutTypes) ) { $layoutType = 'classic'; } // Store the layout type for future use. $_SESSION['layoutType'] = $layoutType; return $layoutType; } /** * End helper functions. */ // Let's roll. Call this function! $layoutType = initLayoutType(); /** * * Example of layout switch links. * Eg. ['Classic' | Mobile | 'Tablet'] * */ ?>

Demo page number one.

You can go to page two.

Showing you the version.

Note: When running this test using the same browser with multiple User-Agents, clear your cookies/session before each test.

Demo page number two.

You can go back to page one.

Showing you the version.