 |
|
08-29-2009, 05:27 PM
|
|
#1
|
 |
|
Novice (Level 1)
Join Date: Aug 2009
Location: Long Island, NY
Posts: 5
|
help pls: redirect depending on DEVICE (not just browser)
im stumped on this...
my goal is to redirect visitors to my .mobi site if their on a mobile device and if on a computer to do nothing at all.
for the past 2 yrs ive had mobile devices redirected to mysite.com/mobile. now as im upgrading to a .mobi i want to be more specific, now all i need is to learn how to get it done! (i prefer php over javascript for obvious reasons)
can someone help me complete the following please??:
PHP Code:
<?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;
}
if($mobile_browser>0) {
// do something
}
else {
// do something else
}
?>
thanks in advance,
-c. a. a.
|
|
Add to del.icio.us
Can you digg it?
|
|
|
08-29-2009, 09:35 PM
|
|
#2
|
 |
|
Catapulted
Join Date: Dec 2005
Location: Within the division of zero
Posts: 5,859
|
So instead of redirecting to mysite.com/mobile, redirect to mysite.mobi/. Right?
|
|
Add to del.icio.us
Can you digg it?
|
|
|
08-30-2009, 04:36 PM
|
|
#3
|
 |
|
Novice (Level 1)
Join Date: Aug 2009
Location: Long Island, NY
Posts: 5
|
Quote:
Originally Posted by erisco
So instead of redirecting to mysite.com/mobile, redirect to mysite.mobi/. Right?
|
thats correct
|
|
Add to del.icio.us
Can you digg it?
|
|
|
08-30-2009, 07:04 PM
|
|
#4
|
 |
|
Catapulted
Join Date: Dec 2005
Location: Within the division of zero
Posts: 5,859
|
Okay, so why can you not apply the mechanism used previously in this new situation?
Redirects can by done by sending the browser a location header with the header() function.
|
|
Add to del.icio.us
Can you digg it?
|
|
|
08-30-2009, 10:18 PM
|
|
#5
|
 |
|
Novice (Level 1)
Join Date: Aug 2009
Location: Long Island, NY
Posts: 5
|
Quote:
Originally Posted by erisco
Okay, so why can you not apply the mechanism used previously in this new situation?
Redirects can by done by sending the browser a location header with the header() function.
|
im sorry, i explained this wrong... for the past 2 years ive had a link immediately following my <body> tag - similar to 'if your on a mobile device please click here'
i have yet to successfully redirect ONLY mobile devices. for example, when i run sample redirection scripts and test them from:
1) blackberry curve on its default browser = i dont redirect, the script thinks im using an old version of netscape
2) the same blackberry using opera mini = redirects properly
3) an iphone = redirects properly
thanks for your help - and sorry for not accurately explaining my scenario the first time.
|
|
Add to del.icio.us
Can you digg it?
|
|
|
08-31-2009, 10:59 AM
|
|
#6
|
 |
|
Catapulted
Join Date: Dec 2005
Location: Within the division of zero
Posts: 5,859
|
I personally am not aware of the issues with detecting handheld devices based on their UA string. However, what I do not understand, is why you are not just providing an alternative style sheet for handheld users. Why is there the need to redirect at all?
|
|
Add to del.icio.us
Can you digg it?
|
|
 |
|
KEEP TABS |
|
SPONSORS |
| |


|
| |
|
|
| |
|