Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Microsoft Edge regex for user agent

Is there a fool-proof regex (I'm using PHP) to match the Microsoft Edge user agent string?

like image 585
GluePear Avatar asked Aug 11 '15 19:08

GluePear


People also ask

What is the user agent string for Edge?

Microsoft Edge UA string:2171.71 Safari/537.36 Edge/12.0″.

What is AppleWebKit 537.36 Khtml like Gecko used for?

AppleWebKit/537.36 indicates what browser rendering engine is used. A rendering engine is what transforms HTML into an interactive webpage on the user's screen. The WebKit browser engine was developed by Apple and is primarily used by Safari, Chromium, and all other WebKit-based browsers. (KHTML, like Gecko).

How do I change browser agent in edge?

Press Ctrl + Shift + P (Windows, Linux) or Command + Shift + P (macOS) to open the Command Menu. Type network conditions , select Show Network conditions, and then press Enter to open the Network conditions tool. In the User agent section, clear the Use browser default checkbox.

What is user agent string?

The User-Agent (UA) string is contained in the HTTP headers and is intended to identify devices requesting online content. The User-Agent tells the server what the visiting device is (among many other things) and this information can be used to determine what content to return.


2 Answers

As well most browsers you can simply just say the browser name in the comparison string as shown below.

$user_agent = $_SERVER['HTTP_USER_AGENT']; 
preg_match('/Edge/i', $user_agent)

This worked for me. Hope it does for you too.

like image 61
Kevin Kennedy Avatar answered Oct 16 '22 02:10

Kevin Kennedy


I would HIGHLY recommend

  1. not using us-sniffing. There is almost no reason to do so.
  2. if you absolutely really have to, using a library like ua-parser rather than rolling your own.
like image 30
Patrick Avatar answered Oct 16 '22 03:10

Patrick