Click to See Complete Forum and Search --> : Mobile Site Redirects


grimmylina
09-30-2010, 02:17 PM
Hi,

I've been trying to find a good redirect code for our website....Something that would automatically know that you are on a mobile device and send a visitor to either our normal website or to our mobile site.

I am currently using this PHP code below and it seems to work okay but if anybody has better suggestions I am totally open. I did find this javascript somewhere but not sure if it serves my purpose :confused: :

<script type="text/javascript">
if (screen.width<600)
window.location = "./mobile/web/";
</script>

--------------------------------------------------------------------------------------

<?php

$mobile_browser = '0';

if(preg_match('/(up.browser|up.link|mmp|symbian|smartphone|midp|wap|phone)/i', strtolower($_SERVER['HTTP_USER_AGENT']))) {
$mobile_browser++;
}

if((strpos(strtolower($_SERVER['HTTP_ACCEPT']),'application/vnd.wap.xhtml+xml')>0) or ((isset($_SERVER['HTTP_X_WAP_PROFILE']) or isset($_SERVER['HTTP_PROFILE'])))) {
$mobile_browser++;
}

$mobile_ua = strtolower(substr($_SERVER['HTTP_USER_AGENT'],0,4));
$mobile_agents = array(
'w3c ','acs-','alav','alca','amoi','audi','avan','benq','bird','blac',
'blaz','brew','cell','cldc','cmd-','dang','doco','eric','hipt','inno',
'ipaq','java','jigs','kddi','keji','leno','lg-c','lg-d','lg-g','lge-',
'maui','maxo','midp','mits','mmef','mobi','mot-','moto','mwbp','nec-',
'newt','noki','oper','palm','pana','pant','phil','play','port','prox',
'qwap','sage','sams','sany','sch-','sec-','send','seri','sgh-','shar',
'sie-','siem','smal','smar','sony','sph-','symb','t-mo','teli','tim-',
'tosh','tsm-','upg1','upsi','vk-v','voda','wap-','wapa','wapi','wapp',
'wapr','webc','winw','winw','xda','xda-');

if(in_array($mobile_ua,$mobile_agents)) {
$mobile_browser++;
}

if (strpos(strtolower($_SERVER['ALL_HTTP']),'OperaMini')>0) {
$mobile_browser++;
}

if (strpos(strtolower($_SERVER['HTTP_USER_AGENT']),'windows')>0) {
$mobile_browser=0;
}

else {
if($mobile_browser>0) {
header("Location: http://chelseahotel.mobi/"); /* Redirect browser */
exit; /* Make sure that code below does not get executed after redirect. */
}
}

?>

elricho
10-12-2010, 10:22 PM
Check out Handset Detection (www.handsetdetection.com). There's a javascript redirection creator and just a few lines to cut and paste into your page head. Its always updated with the latest browsers so there's nothing to change.

grimmylina
10-16-2010, 12:22 PM
Oh, thank you!! I bought a mobile website template and they included a php redirection file.

grimmylina
12-14-2010, 07:20 AM
Check out Handset Detection (www.handsetdetection.com). There's a javascript redirection creator and just a few lines to cut and paste into your page head. Its always updated with the latest browsers so there's nothing to change.

Just tried this out....It's great!!! Thanks for the tip!!!! I looovveeee it!! :D