I'm interested to know whether the user-agent is "Chrome" at the server end using PHP. Is there a reliable regular expression for parsing out the user-agent string from the request header?
Google Chrome Chrome's user agent switcher is part of its Developer Tools. Open them by clicking the menu button and selecting More Tools > Developer Tools. You can also use press Ctrl+Shift+I on your keyboard.
@Tuga: If the string starts with 'Chrome' , strpos() returns 0. Since 0 == false , the if code won't run, but you want it to. The function returns an actual false if the string isn't found, so you have to compare it by type using !==
The get_browser() function in PHP is an inbuilt function that is used to tell the user about the browser's capabilities. This function looks up the user's browscap. ini file and returns the capabilities of the user's browser.
# Chrome for Android Chrome for Android reports its UA in the following formats, depending on whether the device is a phone or a tablet. If you are parsing user agent strings using regular expressions, the following can be used to check against Chrome on Android phones and tablets: Phone pattern: 'Android' + 'Chrome/[.
At this point, too many browsers are pretending to be Chrome in order to ride on its popularity as well as combating abuse of browser detection for a simple match for "Chrome" to be effective anymore. I would recommend feature detection going forward, but Chrome (and WebKit/Blink in general) is notorious for lying to feature detection mechanisms as well, so even that isn't as great as it's cracked up to be anymore either.
I can only recommend staying on top of things by comparing its known UA strings with those of other browsers through third-party sites, and creating patterns from there. How you do this depends entirely on the strings themselves. Just keep in mind that due to the nature of browsers, and UA strings, there can never be a "reliable" regular expression for matching them.
In PHP, the relevant server var is $_SERVER['HTTP_USER_AGENT']
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With