Search code examples
phpregexmobilebrowseruser-agent

Which Mobile Browser User Agent string starts with HTTP?


Disclaimer: I don't want to discuss if it's good or bad to use User Agent sniffing to detect Mobile Browsers!

There's a widely adopted RegEx (regular Expression) to detect a Mobile Browser by its User Agent string that you can download from a site like this.

And it contains a group /ht(c(\-| |_|a|g|p|s|t)|tp)/i matching a string starting with "HTTP".

Thus a bot or service using the PHP Pear module HTTP_Request2 using a string like HTP_Request2/2.1.1 (http://pear.php.net/package/http_request2) PHP/5.3.2-1ubuntu4.15 would be detected as Mobile Browser and redirected to the websites mobile URL.

Question: What mobile browser is detected that way? What would that User Agent string of that mobile browser look like? (bonus: What needs to be changed to not match HTTP_Request2 but the Mobile Browser?)


Solution

  • Looks like it matches http://www.voxtel.ru/UAProf/Voxtel_*.xml for some reason, and that is all I could see that start with http. You can see them in the useragents.txt file from that site. There are many others that contain http or HTTP later in the string though.

    You could probably change the pattern, as I wouldn't rely on http somewhere in the user-agent string to determine if it's a mobile device:

    /ht(c(-| |_|a|g|p|s|t))/i