What Does Your User Agent Say About You?


A user agent is a computer program representing a person, for example, a browser in a Web context.

Besides a browser, a user agent could be a bot scraping webpages, a download manager, or another app accessing the Web. Along with each request they make to the server, browsers include a self-identifying User-Agent HTTP header called a user agent (UA) string. This string often identifies the browser, its version number, and its host operating system.

Spam bots, download managers, and some browsers often send a fake UA string to announce themselves as a different client. This is known as user agent spoofing.

The user agent string can be accessed with JavaScript on the client side using the navigator.userAgent property.

A typical user agent string looks like this: "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:35.0) Gecko/20100101 Firefox/35.0".


User Agent String

Browser Data

User Agent Php

Danielle Fletcher
• Tuesday, 17 November, 2020
• 7 min read

Making statements based on opinion; back them up with references or personal experience. The most robust way to do it is with curl and based on how complex the query is, maybe your only option.

parse agent user effort minimal


Yes, this function also opens files from URLs, assuming the option is enabled in the config. Including headers is something that is fairly easy to do, but it is not entirely straight forward with PHP.

This guide will show you how to set a custom user agent header to PHP HTTP requests. As a quick recap, an user agent is a string that is sent as a header in an HTTP request.

It is never wise to build security based on this alone, but if you want to block bots, the user agent is usually the place to start. The code below will show you a fairly simple curl request that has a custom user agent defined.

On top of being able to fetch HTML, JSON or any format from a URL, you can also pass headers in this request. This is not a guaranteed solution but provides an overall accurate way to detect what browser a user is using.

This is not a guaranteed solution but provides an overall accurate way to detect what browser a user is using. API, based on Laravel framework and Matomo DeviceDetector, that returns info about users devices in JSON format, when you put Sergeant in GET-parameters.

user agent browser parse string useragent parser

API, Laravel Matomo DeviceDetector, JSON, Sergeant. Anonymous ¶ Follow up to Francesco R's post from 2016. His function works for most human traffic; added a few lines to cover the most common bot traffic.

Also fixed issue with function failing to detect strings at position 0 due to strops behavior. Ruudrp at live dot NL ¶ To my surprise I found that none of the get_browser alternatives output the correct name / version combination that I was looking for using Opera or Chrome.

They either give the wrong name e.g. Safari when in fact it should be Chrome and if the UA string includes a version number as with the latest versions of Chrome and Opera the wrong number is reported. So I took bits and pieces from the various examples and combined them and added a check for version.

“;} return array('sergeant' EU_ agent,'name' name,'version' version,'platform' platform,'pattern' pattern);} UA=browser();$yourbrowser= “Your browser: ". Francesco R ¶ If you ONLY need a very fast and simple function to detect the browser name (update to May 2016):function get_browser_name($ user _ agent){ if (strops($ user _ agent, 'Opera') || strops($ user _ agent, 'Or/')) return 'Opera'; else if (strops($ user _ agent, 'Edge')) return 'Edge'; else if (strops($ user _ agent, 'Chrome')) return 'Chrome'; else if (strops($ user _ agent, 'Safari')) return 'Safari'; else if (strops($ user _ agent, 'Firefox')) return 'Firefox'; else if (strops($ user _ agent, 'MSI') || strops($ user _ agent, 'Trident/7')) return 'Internet Explorer'; return 'Other';}echo get_browser_name($_SERVER);?>This function also resolves the trouble with Edge (that contains in the user agent the string “Safari” and “Chrome”), with Chrome (contains the string “Safari”) and IE11 (that do not contain 'MSI' like all other IE versions). Note that “strops” is the fastest function to check a string (far better than “prey_match”) and Opera + Edge + Chrome + Safari + Firefox + Internet Explorer are the most used browsers today (over 97%).

The latest version of PHP has a performance fix for this function. Jeff Williams ¶ To automatically update your browscap.ini file on Linux servers, you can use this simple shell script:You can put it in the weekly cron job folder usually located in /etc/iron.weekly just don't forget to make the script executable (ch mod 775 script name).


Tim at digital dot DE ¶ Be aware that loading PHP _browscap.ini via the brows cap PHP .ini setting may consume a non-trivial amount of memory. Current versions are several MB in size (even the “lite” one) and can eat tens of MB of RAM in each PHP process.

I’d recommend comparing your processes’ memory consumption with and without PHP _browscap.ini being loaded. If necessary, consider creating your own stripped-down copy of PHP _browscap.ini with just the browsers that are important to you.

'UserAgent' EU_ agent,'name' name,'version' version,'platform' platform,'pattern' pattern);} UA=browser();$yourbrowser= “Your browser: ". Max at expert dot DE ¶ Be aware of the fact that this function shows what a specific browser might be able to show, but NOT what the user has turned on/off. So maybe this function tells you that the browser is Abel to JavaScript even when JavaScript is turned off by the user.

If (strops($ user _ agent, 'Trident/7.0; RV:')) {content_nav = 'Trident/7.0; RV:';} else if (strops($ user _ agent, 'Trident/7')) {content_nav = 'Trident/7';} else {content_nav = 'Opera';} Good practice would be to include HTML if-statements for IE stylesheets as well as dynamically checking the browser type.

P2 at eduardoruiz dot BS ¶ BE CAREFUL WITH THIS FUNCTION! ! This function uses a lot of CPU and RAM on the whole server resources. Perhaps if you use this function a few times then no problem, but NOT if you use at any page request, or once per session. Also, this function doesn't work correctly and may returns wrong values, wildcards or empty, so it's not very useful for web statistics.

user agent detect javascript mobile read

Jeremie dot Legrand at komori-chambon dot for ¶ Be careful if you use the “Full” Brows cap In file in your PHP .ini config: I wondered why each Apache thread took 350 MB RAM on my server until I changed the “Full” version by the “Lite” one (45 MB to 0.7 MB)Now, each thread takes only 16 MB... So if it is enough for you, use the Lite version! Look around to find user agents for whatever browser, operating system, device, software type or layout engine you need.

$_SERVER is an array containing information such as headers, paths, and script locations. That said, many these variables are accounted for in the CGI/1.1 specification, so you should be able to expect those.

Note that few, if any, of these will be available (or indeed have any meaning) if running PHP on the command line. ' PHP _SELF The filename of the currently executing script, relative to the document root.

SERVER_ADDR The IP address of the server under which the current script is executing. ' Note : Under Apache 2, you must set UseCanonicalName = On and Serenade.

' SERVER_SOFTWARE Server identification string, given in the headers when responding to requests. ' SERVER_PROTOCOL Name and revision of the information protocol via which the page was requested; e.g. HTTP/1.0 '; REQUEST_METHOD Which request method was used to access the page; e.g. GET ', ' HEAD ', POST ', PUT '.

agent api lookup using

REMOTE_ADDR The IP address from which the user is viewing the current page. ' Note : Your web server must be configured to create this variable.

' REMOTE_PORT The port being used on the user's machine to communicate with the web server. ' If a script is executed with the CLI, as a relative path, such as file.

' SERVER_ADMIN The value given to the SERVER_ADMIN (for Apache) directive in the web server configuration file. For default setups, this will be 80 '; using SSL, for instance, will change this to whatever your defined secure HTTP port is.

PATH_TRANSLATED File system- (not document root-) based path to the current script, after the server has done any virtual-to-real mapping. Note : Apache 2 users may use AcceptPathInfo = On inside HTTP.cone to define PATH_INFO.

PHP _AUTH_PW When doing HTTP authentication this variable is set to the password provided by the user. ' PATH_INFO Contains any client-provided path name information trailing the actual script filename but preceding the query string, if available.


For instance, if the current script was accessed via the URL PHP /path_info. There is no need to do global variable; to access it within functions or methods.

Look up the browscap.ini file and return the capabilities of the browser: You can bypass this parameter with NULL return_array Optional.

Other Articles You Might Be Interested In

01: Css User Agent Stylesheet Override
02: Vivaldi Change User Agent String
03: Screen Reader User Agent
04: Ios 12 User Agent String
05: Ios 13 Safari User Agent
06: Edge Android Change User Agent
07: Edge Browser User Agent Switcher
08: Edge Change User Agent To Chrome
09: Edge Chrome Change User Agent
10: Edge Chrome Switch User Agent
1 -
2 -
3 -
4 -
5 -
6 -
7 -
8 -
9 -
10 -