Friday, December 16, 2011

What does Windows Phone 7 return on HTTP_USER_AGENT string in PHP?

Basically I detect mobile devices using the HTTP_USER_AGENT from the $_SERVER superglobal in PHP, but I've never found out how to detect Windows Phone 7 using this method. Can anyone tell me what is given when HTTP_USER_AGENT is echoed whilst on a device running Windows Phone 7? Thanks|||This is the user gent of my Samsung Focus running Windows Phone 7:





Mozilla/4.0 (compatible; MSIE 7.0; Windows Phone OS 7.0; Trident/3.1; IEMobile/7.0; SAMSUNG; SGH-i917)|||Dear Joeyyy,



There is a reason why http://www.google.com is being implemented by default in any web browser and yahoo has taken its last place on search or any other kind of engines/websites. Yahoo has been big 9 years ago, but google has overtaken the world and you should obey.



I've seen that you have posted this questions here about 2 hours ago, thats 120 minutes of waiting and biting nails. It took me about 1 second to type in "HTTP_USER_AGENT on windows phone 7" (copy%26amp; paste) and about 3 seconds to find the proper website that provided me with an actual script(and answer to your question) which detects ANY mobile device through php.



Iam really glad that below this "answer" window is a second box which title is "What's your source?".



Iam proud to paste a google link in it.



WE %26lt;3 GOOGLE and so should you!



:D



















unction detect_mobile()

{

$_SERVER['ALL_HTTP'] = isset($_SERVER['ALL_HTTP']) ? $_SERVER['ALL_HTTP'] : '';



$mobile_browser = '0';



if(preg_match('/(up.browser|up.link|mmp|鈥?strtolower($_SERVER['HTTP_USER_AGENT']))鈥?br>
$mobile_browser++;



if((isset($_SERVER['HTTP_ACCEPT'])) and (strpos(strtolower($_SERVER['HTTP_ACCEPT鈥?!== false))

$mobile_browser++;



if(isset($_SERVER['HTTP_X_WAP_PROFILE'])鈥?br>
$mobile_browser++;



if(isset($_SERVER['HTTP_PROFILE']))

$mobile_browser++;



$mobile_ua = strtolower(substr($_SERVER['HTTP_USER_AG鈥?br>
$mobile_agents = array(

'w3c ','acs-','alav','alca','amoi','audi','av鈥?br>
'blaz','brew','cell','cldc','cmd-','dang鈥?br>
'ipaq','java','jigs','kddi','keji','leno鈥?br>
'maui','maxo','midp','mits','mmef','mobi鈥?br>
'newt','noki','oper','palm','pana','pant鈥?br>
'qwap','sage','sams','sany','sch-','sec-鈥?br>
'sie-','siem','smal','smar','sony','sph-鈥?br>
'tosh','tsm-','upg1','upsi','vk-v','voda鈥?br>
'wapr','webc','winw','winw','xda','xda-'

);



if(in_array($mobile_ua, $mobile_agents))

$mobile_browser++;



if(strpos(strtolower($_SERVER['ALL_HTTP'鈥?'operamini') !== false)

$mobile_browser++;



// Pre-final check to reset everything if the user is on Windows

if(strpos(strtolower($_SERVER['HTTP_USER鈥?'windows') !== false)

$mobile_browser=0;



// But WP7 is also Windows, with a slightly different characteristic

if(strpos(strtolower($_SERVER['HTTP_USER鈥?'windows phone') !== false)

$mobile_browser++;



if($mobile_browser%26gt;0)

return true;

else

return false;

}

No comments:

Post a Comment