<?php
if(checkmobile()) header('Location:http://YOURMOBILESITE.com/');
function checkmobile() {
if (isset($_SERVER['HTTP_X_WAP_PROFILE'])) return true;
if (false !== stripos($_SERVER['HTTP_ACCEPT'], 'wap')) return true;
$reject = array(
'Creative AutoUpdate',
'MSIE',
'Trident',
'Gecko'
);
$accept = array(
'iphone',
'midp',
'j2me',
'avantg',
'docomo',
'novarra',
'palmos',
'palmsource',
'240x320',
'opwv',
'chtml',
'pda',
'windows ce',
'mmp/',
'blackberry',
'mib/',
'symbian',
'wireless',
'nokia',
'hand',
'mobi',
'phone',
'cdm',
'up.b',
'audio',
'SIE-',
'SEC-',
'samsung',
'HTC',
'mot-',
'mitsu',
'sagem',
'sony',
'alcatel',
'lg',
'erics',
'vx',
'NEC',
'philips',
'mmm',
'xx',
'panasonic',
'sharp',
'wap',
'sch',
'rover',
'pocket',
'benq',
'java',
'pt',
'pg',
'vox',
'amoi',
'bird',
'compal',
'kg',
'voda',
'sany',
'kdd',
'dbt',
'sendo',
'sgh',
'psp',
'gradi',
'jb',
'moto'
);
$accept_regex = array(
'[\\d]{3}i'
);
if (isset($_SERVER['HTTP_USER_AGENT'])) {
// check for definite rejects
foreach ($reject as $string) {
if (false !== stripos($_SERVER['HTTP_USER_AGENT'], $string)) {
return false;
}
}
// more efficient accept check
foreach ($accept as $string) {
if (false !== stripos($_SERVER['HTTP_USER_AGENT'], $string)) {
return true;
}
}
// use regex only where necessary
foreach ($accept_regex as $string) {
if (preg_match('/'.$string.'/i', $_SERVER['HTTP_USER_AGENT'])) {
return true;
}
}
}
return false;
}
?>
Some sites look good on the PSP though, so feel free to remove it.