Search code examples
javascriptphpwindows-phone

WindowsPhone which user agent is correct?


Anyone know why php and jscript output different user agents?

And also, which one is correct?

PHP

<?php print_r($_SERVER['HTTP_USER_AGENT']); ?>

Output: Mozilla/5.0 (Mobile; Windows Phone 8.1; Android 4.0; ARM; Trident/7.0; Touch; rv:11.0; IEMobile/11.0; Microsoft; Lumia535) like iPhone OS7_0_3 Mac OS X AppleWebKit/537 (KHTML, like Gecko) Mobile Safari/537)

jScript

alert(navigator.userAgent);

Output: Mozilla/5.0 (compatible; MSIE 9.0; Windows Phone OS 7.5; Trident/5.0; IEMobile/9.0; Microsoft; Lumia 535


Solution

  • In our portal, we detect the calling device over the UAS. I have detected some problems with the WP 8.1 user agent string. For WP with IE, set to mobile over the Internet, I receive the "meaningful" UAS:

    Mozilla/5.0 (Mobile; Windows Phone 8.1; Android 4.0; ARM; Trident/7.0; Touch; rv:11.0; IEMobile/11.0; NOKIA; Lumia 930) like iPhone OS 7_0_3 Mac OS X AppleWebKit/537 (KHTML, like Gecko) Mobile Safari/537

    Whereby, if IE mobile is set to "Desktop" or the portal is called over the Intranet, I receive:

    Mozilla/5.0 (Windows NT 6.2; ARM; Trident/7.0; Touch; rv:11.0; WPDesktop; Lumia 930) like Gecko

    So.. the effect was, that our portal has showed the mobile page to iOS, instead of the mobile page to WP. The workaround was to query the UAS for "Windows Phone" before the query for iPhone. It seems as MS tries, to be detected as mobile device on this way (if a page only queries for iOS and Android-devices), what is not nice.
    Therefore, there is not "one" correct UAC, you have to support more than one...