Go Back  HTML Forums - Free Webmaster Forums and Help Forums > WEBSITE DEVELOPMENT > Server Side Programming > PHP Programming
User Name:
Password:
 

Reply
Thread Tools   Display Modes
  View First Unread
 
Old 08-29-2009, 05:27 PM
  #1
c-a-a
Novice (Level 1)
 
c-a-a's Avatar
 
Join Date: Aug 2009
Location: Long Island, NY
Posts: 5
iTrader: (0)
c-a-a is an unknown quantity at this point
Cool 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.
c-a-a is offline   Add to del.icio.us Add to del.icio.us    Can you digg it?Can you digg it? Reply With Quote
Old 08-29-2009, 09:35 PM
  #2
erisco
Catapulted
 
erisco's Avatar
 
Join Date: Dec 2005
Location: Within the division of zero
Posts: 5,859
iTrader: (0)
erisco will become famous soon enougherisco will become famous soon enough
So instead of redirecting to mysite.com/mobile, redirect to mysite.mobi/. Right?
erisco is offline   Add to del.icio.us Add to del.icio.us    Can you digg it?Can you digg it? Reply With Quote
Old 08-30-2009, 04:36 PM
  #3
c-a-a
Novice (Level 1)
 
c-a-a's Avatar
 
Join Date: Aug 2009
Location: Long Island, NY
Posts: 5
iTrader: (0)
c-a-a is an unknown quantity at this point
Quote:
Originally Posted by erisco View Post
So instead of redirecting to mysite.com/mobile, redirect to mysite.mobi/. Right?
thats correct
c-a-a is offline   Add to del.icio.us Add to del.icio.us    Can you digg it?Can you digg it? Reply With Quote
Old 08-30-2009, 07:04 PM
  #4
erisco
Catapulted
 
erisco's Avatar
 
Join Date: Dec 2005
Location: Within the division of zero
Posts: 5,859
iTrader: (0)
erisco will become famous soon enougherisco will become famous soon enough
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.
erisco is offline   Add to del.icio.us Add to del.icio.us    Can you digg it?Can you digg it? Reply With Quote
Old 08-30-2009, 10:18 PM
  #5
c-a-a
Novice (Level 1)
 
c-a-a's Avatar
 
Join Date: Aug 2009
Location: Long Island, NY
Posts: 5
iTrader: (0)
c-a-a is an unknown quantity at this point
Quote:
Originally Posted by erisco View Post
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.
c-a-a is offline   Add to del.icio.us Add to del.icio.us    Can you digg it?Can you digg it? Reply With Quote
Old 08-31-2009, 10:59 AM
  #6
erisco
Catapulted
 
erisco's Avatar
 
Join Date: Dec 2005
Location: Within the division of zero
Posts: 5,859
iTrader: (0)
erisco will become famous soon enougherisco will become famous soon enough
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?
erisco is offline   Add to del.icio.us Add to del.icio.us    Can you digg it?Can you digg it? Reply With Quote

Reply
KEEP TABS
SPONSORS
 
Boxedart



 
 


 
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
  
 
 
 



 
  POSTING RULES
 
 
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Thread Tools
Display Modes

Forum Jump

 

All times are GMT -5. The time now is 02:34 AM.

   

Mascot team created by Drawshop.com

Powered by vBulletin® Version 3.6.7
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.

Server Monitoring by ENIACmonitor 0.01
HTMLforums.com © Big Resources, Inc. Web Design by BoxedArt.com
vRewrite 1.5 beta SEOed URLs completed by Tech Help Forum and Chalo Na.