mobile redirect code

Started on the old forum in July 2009 · view the original in the archive · old links redirect here

18 replies · 5,550 views · started 17 years ago · 1 min read

9 participants
DarkRaven Junior · 11 posts #1
<?php
//compliments of http://www.buchfelder.biz/

$mobile = "http://mobile.fantasyonline.us/";
$text = $_SERVER['HTTP_USER_AGENT'];
$var[0] = 'Mozilla/4.';
$var[1] = 'Mozilla/3.0';
$var[2] = 'AvantGo';
$var[3] = 'ProxiNet';
$var[4] = 'Danger hiptop 1.0';
$var[5] = 'DoCoMo/';
$var[6] = 'Google CHTML Proxy/';
$var[7] = 'UP.Browser/';
$var[8] = 'SEMC-Browser/';
$var[9] = 'J-PHONE/';
$var[10] = 'PDXGW/';
$var[11] = 'ASTEL/';
$var[12] = 'Mozilla/1.22';
$var[13] = 'Handspring';
$var[14] = 'Windows CE';
$var[15] = 'PPC';
$var[16] = 'Mozilla/2.0';
$var[17] = 'Blazer/';
$var[18] = 'Palm';
$var[19] = 'WebPro/';
$var[20] = 'EPOC32-WTL/';
$var[21] = 'Tungsten';
$var[22] = 'Netfront/';
$var[23] = 'Mobile Content Viewer/';
$var[24] = 'PDA';
$var[25] = 'MMP/2.0';
$var[26] = 'Embedix/';
$var[27] = 'Qtopia/';
$var[28] = 'Xiino/';
$var[29] = 'BlackBerry';
$var[30] = 'Gecko/20031007';
$var[31] = 'MOT-';
$var[32] = 'UP.Link/';
$var[33] = 'Smartphone';
$var[34] = 'portalmmm/';
$var[35] = 'Nokia';
$var[36] = 'Symbian';
$var[37] = 'AppleWebKit/413';
$var[38] = 'UPG1 UP/';
$var[39] = 'RegKing';
$var[40] = 'STNC-WTL/';
$var[41] = 'J2ME';
$var[42] = 'Opera Mini/';
$var[43] = 'SEC-';
$var[44] = 'ReqwirelessWeb/';
$var[45] = 'AU-MIC/';
$var[46] = 'Sharp';
$var[47] = 'SIE-';
$var[48] = 'SonyEricsson';
$var[49] = 'Elaine/';
$var[50] = 'SAMSUNG-';
$var[51] = 'Panasonic';
$var[52] = 'Siemens';
$var[53] = 'Sony';
$var[54] = 'Verizon';
$var[55] = 'Cingular';
$var[56] = 'Sprint';
$var[57] = 'AT&T';
$var[58] = 'Nextel';
$var[59] = 'Pocket PC';
$var[60] = 'T-Mobile';	
$var[61] = 'Orange';
$var[62] = 'Casio';
$var[63] = 'HTC';
$var[64] = 'Motorola';
$var[65] = 'Samsung';
$var[66] = 'NEC';

$result = count($var);

for ($i=0;$i<$result;$i++)
{	
	$ausg = stristr($text, $var[$i]);	
	if(strlen($ausg)>0)
	{
		header("location: $mobile");
		echo '<BR>Mobile device detected ... <BR>';
		break;
	}
	
}
?>

for some reason it redirecting ie to mobile

Anshul Senior · 296 posts #2

remove $var[14] = 'Windows CE';

Anshul Senior · 296 posts #3

try this

<?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']),' ppc;')>0) {
    $mobile_browser++;
}
 
if (strpos(strtolower($_SERVER['HTTP_USER_AGENT']),'windows ce')>0) {
    $mobile_browser++;
}
if (strpos(strtolower($_SERVER['HTTP_USER_AGENT']),'windows')>0) {
    $mobile_browser=0;
}
 
if (strpos(strtolower($_SERVER['HTTP_USER_AGENT']),'iemobile')>0) {
    $mobile_browser++;
}
 
if($mobile_browser>0) {
header('Location:http://mobilesite.com');
}
else {
header('Location:http://Internetexplorersite.com');
}
?>
anderson Developer · 146 posts #4

I just tested anshul's code and it's working nice.

Wait...

ifuschini Newbie · 9 posts #5

Apache Mobile Filter

I suggest to use the "Apache Mobile Fillter".

The Apache Mobile Filter allows you to access WURFL from any programming language, not just Java and php that is traditionally used for dynamic mobile web sites.

The module detects the mobile device and passes the WURFL capabilities on to the other web application as environment variables. It can also be used to resize images on the fly to adapt to the screen size of the mobile device. Try it and let me know your opinion.

For more info: Apache Mobile Filter 2.0

I have made two test pages:

PC Test Page: http://apachemobilefilter.nogoogle.it/php_test.php

Mobile Test Page: Apache Mobile Test

kei_ki7 Senior · 431 posts #7

anderson wrote: I just tested anshul's code and it's working nice.

..So why no one thanks him ?? LoL just asking =)

Did I help you? You can help me too Your donations will help me finance my studies.

ifuschini Newbie · 9 posts #8

I don't think is correct, because some mobile browser for example the iPhone don't support wml.

kiLLeR-eyEd_14 Senior · 382 posts #9

kei_ki7 wrote: ..So why no one thanks him ?? LoL just asking =)

why don't you try mine..don't make it hard..it's very simple and easy..you don't need to list down several user agents..Just detect if $http_accept matched with wml and then redirect it to mobile..Although it's mobile, we all know html structure is better than wml..Unless it really doesn't support html..

ifuschini Newbie · 9 posts #10

HTTP_ACCEPT is not a good method to know if a device is a mobile device. A lot of mobile device don'accept wml, so it's not a method to detect device. You need an example ? Try with this devices: Nokia N90 Mozilla/5.0 (SymbianOS/9.1; U; en-us) AppleWebKit/413 (KHTML, like Gecko) Safari/413

Mozilla/4.0 (compatible; MSIE 6.0; X11; Linux armv6l; U) Opera 8.5 [en_US] Maemo browser 0.7.6 RX-34_2007SE_2.2006.51-6

HTC Dreams (android) Mozilla/5.0 (Linux; U; Android 1.0; en-us; dream) AppleWebKit/525.10 (KHTML, like Gecko) Version/3.0.4 Mobile Safari/523.12.2

All of this devices dosen't support wml.

metulj Super moderator Principal · 1,726 posts #11

ifuschini wrote: HTTP_ACCEPT is not a good method to know if a device is a mobile device. A lot of mobile device don'accept wml, so it's not a method to detect device. You need an example ? Try with this devices: Nokia N90 Mozilla/5.0 (SymbianOS/9.1; U; en-us) AppleWebKit/413 (KHTML, like Gecko) Safari/413

Mozilla/4.0 (compatible; MSIE 6.0; X11; Linux armv6l; U) Opera 8.5 [en_US] Maemo browser 0.7.6 RX-34_2007SE_2.2006.51-6

HTC Dreams (android) Mozilla/5.0 (Linux; U; Android 1.0; en-us; dream) AppleWebKit/525.10 (KHTML, like Gecko) Version/3.0.4 Mobile Safari/523.12.2

All of this devices dosen't support wml. so if device doesnt accept WML, it'll be redirected to XHTML site... thats what this is all about..😳

It's better to keep your mouth shut and give the impression that you're stupid, than to open it and remove all doubt. ⓣⓗⓔ ⓠⓤⓘⓔⓣⓔⓡ ⓨⓞⓤ ⓑⓔ©ⓞⓜⓔ, ⓣⓗⓔ ⓜⓞⓡⓔ ⓨⓞⓤ ⓐⓡⓔ ⓐⓑⓛⓔ ⓣⓞ ⓗⓔⓐⓡ ! ιη тнєσяу, тнє ρяα¢тι¢є ιѕ α яєѕυℓт σƒ тнє тнєσяу, вυт ιη ρяα¢тι¢є ιѕ тнє σρρσѕιтє.

キノgんイノ刀g 4 ア乇ムc乇 ノ丂 レノズ乇 キucズノ刀g 4 √ノ尺gノ刀ノイリ!

kiLLeR-eyEd_14 Senior · 382 posts #12

ifuschini wrote: HTTP_ACCEPT is not a good method to know if a device is a mobile device. A lot of mobile device don'accept wml, so it's not a method to detect device. You need an example ? Try with this devices: Nokia N90 Mozilla/5.0 (SymbianOS/9.1; U; en-us) AppleWebKit/413 (KHTML, like Gecko) Safari/413

Mozilla/4.0 (compatible; MSIE 6.0; X11; Linux armv6l; U) Opera 8.5 [en_US] Maemo browser 0.7.6 RX-34_2007SE_2.2006.51-6

HTC Dreams (android) Mozilla/5.0 (Linux; U; Android 1.0; en-us; dream) AppleWebKit/525.10 (KHTML, like Gecko) Version/3.0.4 Mobile Safari/523.12.2

All of this devices dosen't support wml.

You said they doesn't support wml?then they will be redirected to xhtml..what's wrong?lol..Metulj is right..

ifuschini Newbie · 9 posts #14

I mean that a mobile could be xhtml and wml. Look wurfl.sourceforge.net probably is more clear.

kiLLeR-eyEd_14 Senior · 382 posts #16

ifuschini wrote: I mean that a mobile could be xhtml and wml. Look wurfl.sourceforge.net probably is more clear.

look at my site to see what you mean..http://yuhjiwap.co.cc..And yeh, mobile can be wml or xhtml..Only if it supports both wml and xhtml..Otherwise, it can be wml or xhtml only..

kiss Senior · 294 posts #17
<?php

function mobile_device_detect($iphone=true,$android=true,$opera=true,$blackberry=true,$palm=true,$windows=true,$mobileredirect=false,$desktopredirect=false){

  $mobile_browser   = false; // set mobile browser as false till we can prove otherwise
  $user_agent       = $_SERVER['HTTP_USER_AGENT']; // get the user agent value - this should be cleaned to ensure no nefarious input gets executed
  $accept           = $_SERVER['HTTP_ACCEPT']; // get the content accept value - this should be cleaned to ensure no nefarious input gets executed

  switch(true){ // using a switch against the following statements which could return true is more efficient than the previous method of using if statements

    case (eregi('ipod',$user_agent)||eregi('iphone',$user_agent)); // we find the words iphone or ipod in the user agent
      $mobile_browser = $iphone; // mobile browser is either true or false depending on the setting of iphone when calling the function
      if(substr($iphone,0,4)=='http'){ // does the value of iphone resemble a url
        $mobileredirect = $iphone; // set the mobile redirect url to the url value stored in the iphone value
      } // ends the if for iphone being a url
    break; // break out and skip the rest if we've had a match on the iphone or ipod

    case (eregi('android',$user_agent));  // we find android in the user agent
      $mobile_browser = $android; // mobile browser is either true or false depending on the setting of android when calling the function
      if(substr($android,0,4)=='http'){ // does the value of android resemble a url
        $mobileredirect = $android; // set the mobile redirect url to the url value stored in the android value
      } // ends the if for android being a url
    break; // break out and skip the rest if we've had a match on android

    case (eregi('opera mini',$user_agent)); // we find opera mini in the user agent
      $mobile_browser = $opera; // mobile browser is either true or false depending on the setting of opera when calling the function
      if(substr($opera,0,4)=='http'){ // does the value of opera resemble a rul
        $mobileredirect = $opera; // set the mobile redirect url to the url value stored in the opera value
      } // ends the if for opera being a url 
    break; // break out and skip the rest if we've had a match on opera

    case (eregi('blackberry',$user_agent)); // we find blackberry in the user agent
      $mobile_browser = $blackberry; // mobile browser is either true or false depending on the setting of blackberry when calling the function
      if(substr($blackberry,0,4)=='http'){ // does the value of blackberry resemble a rul
        $mobileredirect = $blackberry; // set the mobile redirect url to the url value stored in the blackberry value
      } // ends the if for blackberry being a url 
    break; // break out and skip the rest if we've had a match on blackberry

    case (preg_match('/(palm os|palm|hiptop|avantgo|plucker|xiino|blazer|elaine)/i',$user_agent)); // we find palm os in the user agent - the i at the end makes it case insensitive
      $mobile_browser = $palm; // mobile browser is either true or false depending on the setting of palm when calling the function
      if(substr($palm,0,4)=='http'){ // does the value of palm resemble a rul
        $mobileredirect = $palm; // set the mobile redirect url to the url value stored in the palm value
      } // ends the if for palm being a url 
    break; // break out and skip the rest if we've had a match on palm os

    case (preg_match('/(windows ce; ppc;|windows ce; smartphone;|windows ce; iemobile)/i',$user_agent)); // we find windows mobile in the user agent - the i at the end makes it case insensitive
      $mobile_browser = $windows; // mobile browser is either true or false depending on the setting of windows when calling the function
      if(substr($windows,0,4)=='http'){ // does the value of windows resemble a rul
        $mobileredirect = $windows; // set the mobile redirect url to the url value stored in the windows value
      } // ends the if for windows being a url 
    break; // break out and skip the rest if we've had a match on windows

    case (preg_match('/(up.browser|up.link|mmp|symbian|smartphone|midp|wap|vodafone|o2|pocket|kindle|mobile|pda|psp|treo)/i',$user_agent)); // check if any of the values listed create a match on the user agent - these are some of the most common terms used in agents to identify them as being mobile devices - the i at the end makes it case insensitive
      $mobile_browser = true; // set mobile browser to true
    break; // break out and skip the rest if we've preg_match on the user agent returned true 

    case ((strpos($accept,'text/vnd.wap.wml')>0)||(strpos($accept,'application/vnd.wap.xhtml+xml')>0)); // is the device showing signs of support for text/vnd.wap.wml or application/vnd.wap.xhtml+xml
      $mobile_browser = true; // set mobile browser to true
    break; // break out and skip the rest if we've had a match on the content accept headers

    case (isset($_SERVER['HTTP_X_WAP_PROFILE'])||isset($_SERVER['HTTP_PROFILE'])); // is the device giving us a HTTP_X_WAP_PROFILE or HTTP_PROFILE header - only mobile devices would do this
      $mobile_browser = true; // set mobile browser to true
    break; // break out and skip the final step if we've had a return true on the mobile specfic headers

    case (in_array(strtolower(substr($user_agent,0,4)),array('1207'=>'1207','3gso'=>'3gso','4thp'=>'4thp','501i'=>'501i','502i'=>'502i','503i'=>'503i','504i'=>'504i','505i'=>'505i','506i'=>'506i','6310'=>'6310','6590'=>'6590','770s'=>'770s','802s'=>'802s','a wa'=>'a wa','acer'=>'acer','acs-'=>'acs-','airn'=>'airn','alav'=>'alav','asus'=>'asus','attw'=>'attw','au-m'=>'au-m','aur '=>'aur ','aus '=>'aus ','abac'=>'abac','acoo'=>'acoo','aiko'=>'aiko','alco'=>'alco','alca'=>'alca','amoi'=>'amoi','anex'=>'anex','anny'=>'anny','anyw'=>'anyw','aptu'=>'aptu','arch'=>'arch','argo'=>'argo','bell'=>'bell','bird'=>'bird','bw-n'=>'bw-n','bw-u'=>'bw-u','beck'=>'beck','benq'=>'benq','bilb'=>'bilb','blac'=>'blac','c55/'=>'c55/','cdm-'=>'cdm-','chtm'=>'chtm','capi'=>'capi','comp'=>'comp','cond'=>'cond','craw'=>'craw','dall'=>'dall','dbte'=>'dbte','dc-s'=>'dc-s','dica'=>'dica','ds-d'=>'ds-d','ds12'=>'ds12','dait'=>'dait','devi'=>'devi','dmob'=>'dmob','doco'=>'doco','dopo'=>'dopo','el49'=>'el49','erk0'=>'erk0','esl8'=>'esl8','ez40'=>'ez40','ez60'=>'ez60','ez70'=>'ez70','ezos'=>'ezos','ezze'=>'ezze','elai'=>'elai','emul'=>'emul','eric'=>'eric','ezwa'=>'ezwa','fake'=>'fake','fly-'=>'fly-','fly_'=>'fly_','g-mo'=>'g-mo','g1 u'=>'g1 u','g560'=>'g560','gf-5'=>'gf-5','grun'=>'grun','gene'=>'gene','go.w'=>'go.w','good'=>'good','grad'=>'grad','hcit'=>'hcit','hd-m'=>'hd-m','hd-p'=>'hd-p','hd-t'=>'hd-t','hei-'=>'hei-','hp i'=>'hp i','hpip'=>'hpip','hs-c'=>'hs-c','htc '=>'htc ','htc-'=>'htc-','htca'=>'htca','htcg'=>'htcg','htcp'=>'htcp','htcs'=>'htcs','htct'=>'htct','htc_'=>'htc_','haie'=>'haie','hita'=>'hita','huaw'=>'huaw','hutc'=>'hutc','i-20'=>'i-20','i-go'=>'i-go','i-ma'=>'i-ma','i230'=>'i230','iac'=>'iac','iac-'=>'iac-','iac/'=>'iac/','ig01'=>'ig01','im1k'=>'im1k','inno'=>'inno','iris'=>'iris','jata'=>'jata','java'=>'java','kddi'=>'kddi','kgt'=>'kgt','kgt/'=>'kgt/','kpt '=>'kpt ','kwc-'=>'kwc-','klon'=>'klon','lexi'=>'lexi','lg g'=>'lg g','lg-a'=>'lg-a','lg-b'=>'lg-b','lg-c'=>'lg-c','lg-d'=>'lg-d','lg-f'=>'lg-f','lg-g'=>'lg-g','lg-k'=>'lg-k','lg-l'=>'lg-l','lg-m'=>'lg-m','lg-o'=>'lg-o','lg-p'=>'lg-p','lg-s'=>'lg-s','lg-t'=>'lg-t','lg-u'=>'lg-u','lg-w'=>'lg-w','lg/k'=>'lg/k','lg/l'=>'lg/l','lg/u'=>'lg/u','lg50'=>'lg50','lg54'=>'lg54','lge-'=>'lge-','lge/'=>'lge/','lynx'=>'lynx','leno'=>'leno','m1-w'=>'m1-w','m3ga'=>'m3ga','m50/'=>'m50/','maui'=>'maui','mc01'=>'mc01','mc21'=>'mc21','mcca'=>'mcca','medi'=>'medi','meri'=>'meri','mio8'=>'mio8','mioa'=>'mioa','mo01'=>'mo01','mo02'=>'mo02','mode'=>'mode','modo'=>'modo','mot '=>'mot ','mot-'=>'mot-','mt50'=>'mt50','mtp1'=>'mtp1','mtv '=>'mtv ','mate'=>'mate','maxo'=>'maxo','merc'=>'merc','mits'=>'mits','mobi'=>'mobi','motv'=>'motv','mozz'=>'mozz','n100'=>'n100','n101'=>'n101','n102'=>'n102','n202'=>'n202','n203'=>'n203','n300'=>'n300','n302'=>'n302','n500'=>'n500','n502'=>'n502','n505'=>'n505','n700'=>'n700','n701'=>'n701','n710'=>'n710','nec-'=>'nec-','nem-'=>'nem-','newg'=>'newg','neon'=>'neon','netf'=>'netf','noki'=>'noki','nzph'=>'nzph','o2 x'=>'o2 x','o2-x'=>'o2-x','opwv'=>'opwv','owg1'=>'owg1','opti'=>'opti','oran'=>'oran','p800'=>'p800','pand'=>'pand','pg-1'=>'pg-1','pg-2'=>'pg-2','pg-3'=>'pg-3','pg-6'=>'pg-6','pg-8'=>'pg-8','pg-c'=>'pg-c','pg13'=>'pg13','phil'=>'phil','pn-2'=>'pn-2','pt-g'=>'pt-g','palm'=>'palm','pana'=>'pana','pire'=>'pire','pock'=>'pock','pose'=>'pose','psio'=>'psio','qa-a'=>'qa-a','qc-2'=>'qc-2','qc-3'=>'qc-3','qc-5'=>'qc-5','qc-7'=>'qc-7','qc07'=>'qc07','qc12'=>'qc12','qc21'=>'qc21','qc32'=>'qc32','qc60'=>'qc60','qci-'=>'qci-','qwap'=>'qwap','qtek'=>'qtek','r380'=>'r380','r600'=>'r600','raks'=>'raks','rim9'=>'rim9','rove'=>'rove','s55/'=>'s55/','sage'=>'sage','sams'=>'sams','sc01'=>'sc01','sch-'=>'sch-','scp-'=>'scp-','sdk/'=>'sdk/','se47'=>'se47','sec-'=>'sec-','sec0'=>'sec0','sec1'=>'sec1','semc'=>'semc','sgh-'=>'sgh-','shar'=>'shar','sie-'=>'sie-','sk-0'=>'sk-0','sl45'=>'sl45','slid'=>'slid','smb3'=>'smb3','smt5'=>'smt5','sp01'=>'sp01','sph-'=>'sph-','spv '=>'spv ','spv-'=>'spv-','sy01'=>'sy01','samm'=>'samm','sany'=>'sany','sava'=>'sava','scoo'=>'scoo','send'=>'send','siem'=>'siem','smar'=>'smar','smit'=>'smit','soft'=>'soft','sony'=>'sony','t-mo'=>'t-mo','t218'=>'t218','t250'=>'t250','t600'=>'t600','t610'=>'t610','t618'=>'t618','tcl-'=>'tcl-','tdg-'=>'tdg-','telm'=>'telm','tim-'=>'tim-','ts70'=>'ts70','tsm-'=>'tsm-','tsm3'=>'tsm3','tsm5'=>'tsm5','tx-9'=>'tx-9','tagt'=>'tagt','talk'=>'talk','teli'=>'teli','topl'=>'topl','tosh'=>'tosh','up.b'=>'up.b','upg1'=>'upg1','utst'=>'utst','v400'=>'v400','v750'=>'v750','veri'=>'veri','vk-v'=>'vk-v','vk40'=>'vk40','vk50'=>'vk50','vk52'=>'vk52','vk53'=>'vk53','vm40'=>'vm40','vx98'=>'vx98','virg'=>'virg','vite'=>'vite','voda'=>'voda','vulc'=>'vulc','w3c '=>'w3c ','w3c-'=>'w3c-','wapj'=>'wapj','wapp'=>'wapp','wapu'=>'wapu','wapm'=>'wapm','wig '=>'wig ','wapi'=>'wapi','wapr'=>'wapr','wapv'=>'wapv','wapy'=>'wapy','wapa'=>'wapa','waps'=>'waps','wapt'=>'wapt','winc'=>'winc','winw'=>'winw','wonu'=>'wonu','x700'=>'x700','xda2'=>'xda2','xdag'=>'xdag','yas-'=>'yas-','your'=>'your','zte-'=>'zte-','zeto'=>'zeto','acs-'=>'acs-','alav'=>'alav','alca'=>'alca','amoi'=>'amoi','aste'=>'aste','audi'=>'audi','avan'=>'avan','benq'=>'benq','bird'=>'bird','blac'=>'blac','blaz'=>'blaz','brew'=>'brew','brvw'=>'brvw','bumb'=>'bumb','ccwa'=>'ccwa','cell'=>'cell','cldc'=>'cldc','cmd-'=>'cmd-','dang'=>'dang','doco'=>'doco','eml2'=>'eml2','eric'=>'eric','fetc'=>'fetc','hipt'=>'hipt','http'=>'http','ibro'=>'ibro','idea'=>'idea','ikom'=>'ikom','inno'=>'inno','ipaq'=>'ipaq','jbro'=>'jbro','jemu'=>'jemu','java'=>'java','jigs'=>'jigs','kddi'=>'kddi','keji'=>'keji','kyoc'=>'kyoc','kyok'=>'kyok','leno'=>'leno','lg-c'=>'lg-c','lg-d'=>'lg-d','lg-g'=>'lg-g','lge-'=>'lge-','libw'=>'libw','m-cr'=>'m-cr','maui'=>'maui','maxo'=>'maxo','midp'=>'midp','mits'=>'mits','mmef'=>'mmef','mobi'=>'mobi','mot-'=>'mot-','moto'=>'moto','mwbp'=>'mwbp','mywa'=>'mywa','nec-'=>'nec-','newt'=>'newt','nok6'=>'nok6','noki'=>'noki','o2im'=>'o2im','opwv'=>'opwv','palm'=>'palm','pana'=>'pana','pant'=>'pant','pdxg'=>'pdxg','phil'=>'phil','play'=>'play','pluc'=>'pluc','port'=>'port','prox'=>'prox','qtek'=>'qtek','qwap'=>'qwap','rozo'=>'rozo','sage'=>'sage','sama'=>'sama','sams'=>'sams','sany'=>'sany','sch-'=>'sch-','sec-'=>'sec-','send'=>'send','seri'=>'seri','sgh-'=>'sgh-','shar'=>'shar','sie-'=>'sie-','siem'=>'siem','smal'=>'smal','smar'=>'smar','sony'=>'sony','sph-'=>'sph-','symb'=>'symb','t-mo'=>'t-mo','teli'=>'teli','tim-'=>'tim-','tosh'=>'tosh','treo'=>'treo','tsm-'=>'tsm-','upg1'=>'upg1','upsi'=>'upsi','vk-v'=>'vk-v','voda'=>'voda','vx52'=>'vx52','vx53'=>'vx53','vx60'=>'vx60','vx61'=>'vx61','vx70'=>'vx70','vx80'=>'vx80','vx81'=>'vx81','vx83'=>'vx83','vx85'=>'vx85','wap-'=>'wap-','wapa'=>'wapa','wapi'=>'wapi','wapp'=>'wapp','wapr'=>'wapr','webc'=>'webc','whit'=>'whit','winw'=>'winw','wmlb'=>'wmlb','xda-'=>'xda-',))); // check against a list of trimmed user agents to see if we find a match
      $mobile_browser = true; // set mobile browser to true
    break; // break even though it's the last statement in the switch so there's nothing to break away from but it seems better to include it than exclude it

  } // ends the switch 

  // tell adaptation services (transcoders and proxies) to not alter the content based on user agent as it's already being managed by this script
  header('Cache-Control: no-transform');
  header('Vary: User-Agent, Accept');

  // if redirect (either the value of the mobile or desktop redirect depending on the value of $mobile_browser) is true redirect else we return the status of $mobile_browser
if($redirect = ($mobile_browser==true) ? $mobileredirect : $desktopredirect){
header('Location: '.$redirect); // redirect to the right url for this device
exit;
}else{ 
return $mobile_browser; // will return either true or false 
}
} // ends function mobile_device_detect
?>

www.inbuzunar.mobi -Your mobile portal pocket

ifuschini Newbie · 9 posts #18

I think this code is too complex. I suggest to use my "Apache Mobile Filter", after installation (very simple), you have all the device capabilities as environment variable. And so if you want to control if is a mobile devices you must read this environment variable:

$_SERVER['AMF_IS_WIRELESS_DEVICE'];

I think this code is too complex. I suggest to use my "Apache Mobile Filter" (http://www.idelfuschini.it/apache-mobile-filter-v2x.html?showall=1), after installation (very simple), you have all the device capabilities as environment variable. Is based on WURFL.xml as Device repository. And so if you want to control if is a mobile devices you must read this environment variable:

if ($_SERVER['AMF_IS_WIRELESS_DEVICE'] == true) { // is mobile } else { // is not mobile }

This the other 400 and more cabilities you can find: http://apachemobilefilter.nogoogle.it/php_test.php

Here is the list: AMF_ID, AMF_AAC, AMF_ACCEPT_THIRD_PARTY_COOKIE, AMF_ACCESS_KEY_SUPPORT, AMF_AJAX_MANIPULATE_CSS, AMF_AJAX_MANIPULATE_DOM, AMF_AJAX_SUPPORT_EVENT_LISTENER, AMF_AJAX_SUPPORT_EVENTS, AMF_AJAX_SUPPORT_GETELEMENTBYID, AMF_AJAX_SUPPORT_INNER_HTML, AMF_AJAX_SUPPORT_JAVASCRIPT, AMF_AJAX_XHR_TYPE, AMF_AMR, AMF_ASCII_SUPPORT, AMF_AU, AMF_AWB, AMF_BASIC_AUTHENTICATION_SUPPORT, AMF_BMP, AMF_BRAND_NAME, AMF_BREAK_LIST_OF_LINKS_WITH_BR_ELEMENT_RECOMMENDED, AMF_BUILT_IN_BACK_BUTTON_SUPPORT, AMF_BUILT_IN_CAMERA, AMF_BUILT_IN_RECORDER, AMF_CALLERICON, AMF_CAN_SKIP_ALIGNED_LINK_ROW, AMF_CARD_TITLE_SUPPORT, AMF_CHTML_CAN_DISPLAY_IMAGES_AND_TEXT_ON_SAME_LINE, AMF_CHTML_DISPLAY_ACCESSKEY, AMF_CHTML_DISPLAYS_IMAGE_IN_CENTER, AMF_CHTML_MAKE_PHONE_CALL_STRING, AMF_CHTML_TABLE_SUPPORT, AMF_COLORS, AMF_COLUMNS, AMF_COMPACTMIDI, AMF_CONNECTIONLESS_CACHE_OPERATION, AMF_CONNECTIONLESS_SERVICE_INDICATION, AMF_CONNECTIONLESS_SERVICE_LOAD, AMF_CONNECTIONORIENTED_CONFIRMED_CACHE_OPERATION, AMF_CONNECTIONORIENTED_CONFIRMED_SERVICE_INDICATION, AMF_CONNECTIONORIENTED_CONFIRMED_SERVICE_LOAD, AMF_CONNECTIONORIENTED_UNCONFIRMED_CACHE_OPERATION, AMF_CONNECTIONORIENTED_UNCONFIRMED_SERVICE_INDICATION, AMF_CONNECTIONORIENTED_UNCONFIRMED_SERVICE_LOAD, AMF_COOKIE_SUPPORT, AMF_CSS_SUPPORTS_WIDTH_AS_PERCENTAGE, AMF_DECK_PREFETCH_SUPPORT, AMF_DEVICE_CLAIMS_WEB_SUPPORT, AMF_DIGIPLUG, AMF_DIRECTDOWNLOAD_SUPPORT, AMF_DOJA_1_0, AMF_DOJA_1_5, AMF_DOJA_2_0, AMF_DOJA_2_1, AMF_DOJA_2_2, AMF_DOJA_3_0, AMF_DOJA_3_5, AMF_DOJA_4_0, AMF_DOWNLOADFUN_SUPPORT, AMF_ELECTIVE_FORMS_RECOMMENDED, AMF_EMOJI, AMF_EMPTY_OPTION_VALUE_SUPPORT, AMF_EMPTYOK, AMF_EMS, AMF_EMS_IMELODY, AMF_EMS_ODI, AMF_EMS_UPI, AMF_EMS_VARIABLESIZEDPICTURES, AMF_EPOC_BMP, AMF_EVRC, AMF_EXPIRATION_DATE, AMF_FL_BROWSER, AMF_FL_SCREENSAVER, AMF_FL_STANDALONE, AMF_FL_SUB_LCD, AMF_FL_WALLPAPER, AMF_GIF, AMF_GIF_ANIMATED, AMF_GPRTF, AMF_GREYSCALE, AMF_HAS_POINTING_DEVICE, AMF_HAS_QWERTY_KEYBOARD, AMF_HTML_WEB_3_2, AMF_HTML_WEB_4_0, AMF_HTML_WI_IMODE_COMPACT_GENERIC, AMF_HTML_WI_IMODE_HTML_1, AMF_HTML_WI_IMODE_HTML_2, AMF_HTML_WI_IMODE_HTML_3, AMF_HTML_WI_IMODE_HTML_4, AMF_HTML_WI_IMODE_HTML_5, AMF_HTML_WI_IMODE_HTMLX_1, AMF_HTML_WI_IMODE_HTMLX_1_1, AMF_HTML_WI_OMA_XHTMLMP_1_0, AMF_HTML_WI_W3_XHTMLBASIC, AMF_HTTPS_DETECTABLE, AMF_HTTPS_SUPPORT, AMF_ICONS_ON_MENU_ITEMS_SUPPORT, AMF_IMAGE_AS_LINK_SUPPORT, AMF_IMELODY, AMF_IMODE_REGION, AMF_INLINE_SUPPORT, AMF_INSERT_BR_ELEMENT_AFTER_WIDGET_RECOMMENDED, AMF_IS_TRANSCODER, AMF_IS_WIRELESS_DEVICE, AMF_ISO8859_SUPPORT, AMF_J2ME_3DAPI, AMF_J2ME_3GPP, AMF_J2ME_AAC, AMF_J2ME_AMR, AMF_J2ME_AU, AMF_J2ME_AUDIO_CAPTURE_ENABLED, AMF_J2ME_BMP, AMF_J2ME_BMP3, AMF_J2ME_BTAPI, AMF_J2ME_CAPTURE_IMAGE_FORMATS, AMF_J2ME_CLDC_1_0, AMF_J2ME_CLDC_1_1, AMF_J2ME_DATEFIELD_BROKEN, AMF_J2ME_DATEFIELD_NO_ACCEPTS_NULL_DATE, AMF_J2ME_GIF, AMF_J2ME_GIF89A, AMF_J2ME_H263, AMF_J2ME_HTTP, AMF_J2ME_HTTPS, AMF_J2ME_IMELODY, AMF_J2ME_JPG, AMF_J2ME_JTWI, AMF_J2ME_LOCAPI, AMF_J2ME_MIDI, AMF_J2ME_MIDP_1_0, AMF_J2ME_MIDP_2_0, AMF_J2ME_MMAPI_1_0, AMF_J2ME_MMAPI_1_1, AMF_J2ME_MOTOROLA_LWT, AMF_J2ME_MP3, AMF_J2ME_MP4, AMF_J2ME_MPEG4, AMF_J2ME_NOKIA_UI, AMF_J2ME_PHOTO_CAPTURE_ENABLED, AMF_J2ME_PNG, AMF_J2ME_REAL8, AMF_J2ME_REALAUDIO, AMF_J2ME_REALMEDIA, AMF_J2ME_REALVIDEO, AMF_J2ME_RMF, AMF_J2ME_SERIAL, AMF_J2ME_SIEMENS_COLOR_GAME, AMF_J2ME_SIEMENS_EXTENSION, AMF_J2ME_SOCKET, AMF_J2ME_SVGT, AMF_J2ME_UDP, AMF_J2ME_VIDEO_CAPTURE_ENABLED, AMF_J2ME_WAV, AMF_J2ME_WBMP, AMF_J2ME_WMA, AMF_J2ME_WMAPI_1_0, AMF_J2ME_WMAPI_1_1, AMF_J2ME_WMAPI_2_0, AMF_J2ME_XMF, AMF_JPG, AMF_LARGEOPERATORLOGO, AMF_MAX_DATA_RATE, AMF_MAX_DECK_SIZE, AMF_MAX_IMAGE_HEIGHT, AMF_MAX_IMAGE_WIDTH, AMF_MAX_URL_LENGTH_IN_REQUESTS, AMF_MENU_WITH_LIST_OF_LINKS_RECOMMENDED, AMF_MENU_WITH_SELECT_ELEMENT_RECOMMENDED, AMF_MIDI_MONOPHONIC, AMF_MIDI_POLYPHONIC, AMF_MLD, AMF_MMF, AMF_MMS_3GPP, AMF_MMS_3GPP2, AMF_MMS_AMR, AMF_MMS_BMP, AMF_MMS_EVRC, AMF_MMS_GIF_ANIMATED, AMF_MMS_GIF_STATIC, AMF_MMS_JAD, AMF_MMS_JAR, AMF_MMS_JPEG_BASELINE, AMF_MMS_JPEG_PROGRESSIVE, AMF_MMS_MIDI_MONOPHONIC, AMF_MMS_MIDI_POLYPHONIC, AMF_MMS_MMF, AMF_MMS_MP3, AMF_MMS_MP4, AMF_MMS_NOKIA_3DSCREENSAVER, AMF_MMS_NOKIA_OPERATORLOGO, AMF_MMS_NOKIA_RINGINGTONE, AMF_MMS_NOKIA_WALLPAPER, AMF_MMS_OTA_BITMAP, AMF_MMS_PNG, AMF_MMS_QCELP, AMF_MMS_RMF, AMF_MMS_SPMIDI, AMF_MMS_SYMBIAN_INSTALL, AMF_MMS_VCALENDAR, AMF_MMS_VCARD, AMF_MMS_VIDEO, AMF_MMS_WAV, AMF_MMS_WBMP, AMF_MMS_WBXML, AMF_MMS_WML, AMF_MMS_WMLC, AMF_MMS_XMF, AMF_MP3, AMF_MULTIPART_SUPPORT, AMF_NOKIA_RINGTONE, AMF_NOKIA_VOICE_CALL, AMF_NOKIARING, AMF_NOKIAVCAL, AMF_NOKIAVCARD, AMF_NUMBERED_MENUS, AMF_OMA_SUPPORT, AMF_OMA_V_1_0_COMBINED_DELIVERY, AMF_OMA_V_1_0_FORWARDLOCK, AMF_OMA_V_1_0_SEPARATE_DELIVERY, AMF_OPERATORLOGO, AMF_OPWV_WML_EXTENSIONS_SUPPORT, AMF_OPWV_XHTML_EXTENSIONS_SUPPORT, AMF_PANASONIC, AMF_PDF_SUPPORT, AMF_PHONE_ID_PROVIDED, AMF_PHYSICAL_SCREEN_HEIGHT, AMF_PHYSICAL_SCREEN_WIDTH, AMF_PICTURE, AMF_PICTURE_BMP, AMF_PICTURE_COLORS, AMF_PICTURE_GIF, AMF_PICTURE_GREYSCALE, AMF_PICTURE_JPG, AMF_PICTURE_PNG, AMF_PICTURE_RESIZE, AMF_PICTURE_WBMP, AMF_PICTUREMESSAGE, AMF_PLAYBACK_3G2, AMF_PLAYBACK_3GPP, AMF_PLAYBACK_ACODEC_AAC, AMF_PLAYBACK_ACODEC_AMR, AMF_PLAYBACK_ACODEC_QCELP, AMF_PLAYBACK_MOV, AMF_PLAYBACK_MP4, AMF_PLAYBACK_REAL_MEDIA, AMF_PLAYBACK_VCODEC_H263_0, AMF_PLAYBACK_VCODEC_H263_3, AMF_PLAYBACK_VCODEC_H264_BP, AMF_PLAYBACK_VCODEC_MPEG4_ASP, AMF_PLAYBACK_VCODEC_MPEG4_SP, AMF_PLAYBACK_WMV, AMF_PNG, AMF_POINTING_METHOD, AMF_POST_METHOD_SUPPORT, AMF_PREFERRED_MARKUP, AMF_PROGRESSIVE_DOWNLOAD, AMF_PROPORTIONAL_FONT, AMF_QCELP, AMF_RECEIVER, AMF_RELEASE_DATE, AMF_RESOLUTION_HEIGHT, AMF_RESOLUTION_WIDTH, AMF_RINGTONE, AMF_RINGTONE_3GPP, AMF_RINGTONE_AAC, AMF_RINGTONE_AMR, AMF_RINGTONE_AWB, AMF_RINGTONE_COMPACTMIDI, AMF_RINGTONE_DIGIPLUG, AMF_RINGTONE_IMELODY, AMF_RINGTONE_MIDI_MONOPHONIC, AMF_RINGTONE_MIDI_POLYPHONIC, AMF_RINGTONE_MMF, AMF_RINGTONE_MP3, AMF_RINGTONE_QCELP, AMF_RINGTONE_RMF, AMF_RINGTONE_SPMIDI, AMF_RINGTONE_VOICES, AMF_RINGTONE_WAV, AMF_RINGTONE_XMF, AMF_RMF, AMF_ROWS, AMF_RSS_SUPPORT, AMF_SAGEM_V1, AMF_SAGEM_V2, AMF_SCKL_GROUPGRAPHIC, AMF_SCKL_OPERATORLOGO, AMF_SCKL_RINGTONE, AMF_SCKL_VCALENDAR, AMF_SCKL_VCARD, AMF_SCREENSAVER, AMF_SCREENSAVER_BMP, AMF_SCREENSAVER_COLORS, AMF_SCREENSAVER_GIF, AMF_SCREENSAVER_GREYSCALE, AMF_SCREENSAVER_JPG, AMF_SCREENSAVER_PNG, AMF_SCREENSAVER_RESIZE, AMF_SCREENSAVER_WBMP, AMF_SDIO, AMF_SENDER, AMF_SIEMENS_LOGO_HEIGHT, AMF_SIEMENS_LOGO_WIDTH, AMF_SIEMENS_OTA, AMF_SIEMENS_SCREENSAVER_HEIGHT, AMF_SIEMENS_SCREENSAVER_WIDTH, AMF_SMF, AMF_SOFTKEY_SUPPORT, AMF_SP_MIDI, AMF_STREAMING_3G2, AMF_STREAMING_3GPP, AMF_STREAMING_ACODEC_AAC, AMF_STREAMING_ACODEC_AMR, AMF_STREAMING_FLV, AMF_STREAMING_MOV, AMF_STREAMING_MP4, AMF_STREAMING_PREFERRED_PROTOCOL, AMF_STREAMING_REAL_MEDIA, AMF_STREAMING_REAL_MEDIA_10, AMF_STREAMING_REAL_MEDIA_8, AMF_STREAMING_REAL_MEDIA_9, AMF_STREAMING_VCODEC_H263_0, AMF_STREAMING_VCODEC_H263_3, AMF_STREAMING_VCODEC_H264_BP, AMF_STREAMING_VCODEC_MPEG4_ASP, AMF_STREAMING_VCODEC_MPEG4_SP, AMF_STREAMING_VIDEO, AMF_STREAMING_VIDEO_ACODEC_AAC, AMF_STREAMING_VIDEO_ACODEC_AAC_LTP, AMF_STREAMING_VIDEO_ACODEC_AMR, AMF_STREAMING_VIDEO_ACODEC_AWB, AMF_STREAMING_VIDEO_QCIF, AMF_STREAMING_VIDEO_SQCIF, AMF_STREAMING_VIDEO_VCODEC_H263_0, AMF_STREAMING_VIDEO_VCODEC_H263_3, AMF_STREAMING_VIDEO_VCODEC_H264, AMF_STREAMING_VIDEO_VCODEC_MPEG4, AMF_STREAMING_WMV, AMF_SVGT_1_1, AMF_SVGT_1_1_PLUS, AMF_TABLE_SUPPORT, AMF_TEXT_IMELODY, AMF_TIFF, AMF_TIME_TO_LIVE_SUPPORT, AMF_TIMES_SQUARE_MODE_SUPPORT, AMF_TOTAL_CACHE_DISABLE_SUPPORT, AMF_TRANSCODER_UA_HEADER, AMF_TRANSPARENT_PNG_ALPHA, AMF_TRANSPARENT_PNG_INDEX, AMF_UNIQUE, AMF_UTF8_SUPPORT, AMF_VIDEO, AMF_VIDEO_3GPP, AMF_VIDEO_3GPP2, AMF_VIDEO_ACODEC_AAC, AMF_VIDEO_ACODEC_AAC_LTP, AMF_VIDEO_ACODEC_AMR, AMF_VIDEO_ACODEC_AWB, AMF_VIDEO_ACODEC_QCELP, AMF_VIDEO_DF_SIZE_LIMIT, AMF_VIDEO_MOV, AMF_VIDEO_MP4, AMF_VIDEO_QCIF, AMF_VIDEO_REAL_MEDIA_10, AMF_VIDEO_REAL_MEDIA_8, AMF_VIDEO_REAL_MEDIA_9, AMF_VIDEO_SQCIF, AMF_VIDEO_VCODEC_H263_0, AMF_VIDEO_VCODEC_H263_3, AMF_VIDEO_VCODEC_H264, AMF_VIDEO_VCODEC_MPEG4, AMF_VIDEO_WMV, AMF_VOICES, AMF_VOICEXML, AMF_VPN, AMF_WALLPAPER, AMF_WALLPAPER_BMP, AMF_WALLPAPER_COLORS, AMF_WALLPAPER_GIF, AMF_WALLPAPER_GREYSCALE, AMF_WALLPAPER_JPG, AMF_WALLPAPER_PNG, AMF_WALLPAPER_RESIZE, AMF_WALLPAPER_TIFF, AMF_WALLPAPER_WBMP, AMF_WAP_PUSH_SUPPORT, AMF_WAV, AMF_WBMP, AMF_WIFI, AMF_WIZARDS_RECOMMENDED, AMF_WML_1_1, AMF_WML_1_2, AMF_WML_1_3, AMF_WML_CAN_DISPLAY_IMAGES_AND_TEXT_ON_SAME_LINE, AMF_WML_DISPLAYS_IMAGE_IN_CENTER, AMF_WML_MAKE_PHONE_CALL_STRING, AMF_WRAP_MODE_SUPPORT, AMF_WTA_MISC, AMF_WTA_PDC, AMF_WTA_PHONEBOOK, AMF_WTA_VOICE_CALL, AMF_XHTML_ALLOWS_DISABLED_FORM_ELEMENTS, AMF_XHTML_AUTOEXPAND_SELECT, AMF_XHTML_AVOID_ACCESSKEYS, AMF_XHTML_DISPLAY_ACCESSKEY, AMF_XHTML_DOCUMENT_TITLE_SUPPORT, AMF_XHTML_FILE_UPLOAD, AMF_XHTML_FORMAT_AS_ATTRIBUTE, AMF_XHTML_FORMAT_AS_CSS_PROPERTY, AMF_XHTML_HONORS_BGCOLOR, AMF_XHTML_MAKE_PHONE_CALL_STRING, AMF_XHTML_MARQUEE_AS_CSS_PROPERTY, AMF_XHTML_NOWRAP_MODE, AMF_XHTML_PREFERRED_CHARSET, AMF_XHTML_READABLE_BACKGROUND_COLOR1, AMF_XHTML_READABLE_BACKGROUND_COLOR2, AMF_XHTML_SELECT_AS_DROPDOWN, AMF_XHTML_SELECT_AS_POPUP, AMF_XHTML_SELECT_AS_RADIOBUTTON, AMF_XHTML_SEND_MMS_STRING, AMF_XHTML_SEND_SMS_STRING, AMF_XHTML_SUPPORT_LEVEL, AMF_XHTML_SUPPORT_WML2_NAMESPACE, AMF_XHTML_SUPPORTS_CSS_CELL_TABLE_COLORING, AMF_XHTML_SUPPORTS_FILE_UPLOAD, AMF_XHTML_SUPPORTS_FORMS_IN_TABLE, AMF_XHTML_SUPPORTS_IFRAME, AMF_XHTML_SUPPORTS_INLINE_INPUT, AMF_XHTML_SUPPORTS_INVISIBLE_TEXT, AMF_XHTML_SUPPORTS_MONOSPACE_FONT, AMF_XHTML_SUPPORTS_TABLE_FOR_LAYOUT, AMF_XHTML_TABLE_SUPPORT, AMF_XHTMLMP_PREFERRED_MIME_TYPE, AMF_XMF, AMF_VER, AMF_WURFLVER,

wapnepal Newbie · 5 posts #19

What about .htaccess redirection? Is there any way to detect mobile browsers and pc browsers and redirect mobile browsers to wapsite?

thanks in advance

Sign in to reply.

Similar topics

Keyboard shortcuts

g f
Go to forums
g h
Go to your feed
g m
Go to messages
r
Reply (in a topic)
/
Search
j
Next post
k
Previous post
?
This list
Ctrl/⌘ + Enter
Send what you are writing
Ctrl/⌘ + B / I
Bold / italic while writing
Esc
Close