identify client machine Operating System by using request object in java web applications
Example using the user-agent-utils library:
public class SomeServlet extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String userAgentString = request.getHeader("User-Agent");
UserAgent userAgent = UserAgent.parseUserAgentString(userAgentString);
OperatingSystem os = userAgent.getOperatingSystem();
// Do stuff with os...
}
}
You can read more about the OperatingSystem class here.
You can find the jar here.
How to get browser information of client?
You can install Wangkanai.Detection
package. The full documentation could be found here: https://github.com/wangkanai/Detection
Installation of detection library is now done with a single package
reference point.
PM> install-package Wangkanai.Detection -pre
While it is still possible to install the individual package if you just need that specific resolver.
PM> install-package Wangkanai.Detection.Device -pre
PM> install-package Wangkanai.Detection.Browser -pre
PM> install-package Wangkanai.Detection.Engine -pre //concept
PM> install-package Wangkanai.Detection.Platform -pre //concept
PM> install-package Wangkanai.Detection.Crawler -pre
Installation of Responsive
library will bring in all dependency packages (This will include Wangkanai.Detection.Device
).
PM> install-package Wangkanai.Responsive -pre
I think the following should be enough for you:
install-package Wangkanai.Detection -pre
install-package Wangkanai.Detection.Browser -pre
Then you need to configure the Startup.cs
by adding the detection service in the ConfigureServices
method:
public void ConfigureServices(IServiceCollection services)
{
// Add detection services container and device resolver service.
services.AddDetection();
services.AddDetectionCore().AddBrowser();
// Add framework services.
services.AddMvc();
}
And finally in your Controller
, do something like this:
public class HomeController : Controller
{
private readonly IDetection _detection;
public HomeController(IDetection detection)
{
_detection = detection;
}
public IActionResult Index()
{
string browser_information = _detection.Browser.Type.ToString() +
_detection.Browser.Version;
//...
}
}
How to detect my browser version and operating system using JavaScript?
Detecting browser's details:
var nVer = navigator.appVersion;
var nAgt = navigator.userAgent;
var browserName = navigator.appName;
var fullVersion = ''+parseFloat(navigator.appVersion);
var majorVersion = parseInt(navigator.appVersion,10);
var nameOffset,verOffset,ix;
// In Opera, the true version is after "OPR" or after "Version"
if ((verOffset=nAgt.indexOf("OPR"))!=-1) {
browserName = "Opera";
fullVersion = nAgt.substring(verOffset+4);
if ((verOffset=nAgt.indexOf("Version"))!=-1)
fullVersion = nAgt.substring(verOffset+8);
}
// In MS Edge, the true version is after "Edg" in userAgent
else if ((verOffset=nAgt.indexOf("Edg"))!=-1) {
browserName = "Microsoft Edge";
fullVersion = nAgt.substring(verOffset+4);
}
// In MSIE, the true version is after "MSIE" in userAgent
else if ((verOffset=nAgt.indexOf("MSIE"))!=-1) {
browserName = "Microsoft Internet Explorer";
fullVersion = nAgt.substring(verOffset+5);
}
// In Chrome, the true version is after "Chrome"
else if ((verOffset=nAgt.indexOf("Chrome"))!=-1) {
browserName = "Chrome";
fullVersion = nAgt.substring(verOffset+7);
}
// In Safari, the true version is after "Safari" or after "Version"
else if ((verOffset=nAgt.indexOf("Safari"))!=-1) {
browserName = "Safari";
fullVersion = nAgt.substring(verOffset+7);
if ((verOffset=nAgt.indexOf("Version"))!=-1)
fullVersion = nAgt.substring(verOffset+8);
}
// In Firefox, the true version is after "Firefox"
else if ((verOffset=nAgt.indexOf("Firefox"))!=-1) {
browserName = "Firefox";
fullVersion = nAgt.substring(verOffset+8);
}
// In most other browsers, "name/version" is at the end of userAgent
else if ( (nameOffset=nAgt.lastIndexOf(' ')+1) <
(verOffset=nAgt.lastIndexOf('/')) )
{
browserName = nAgt.substring(nameOffset,verOffset);
fullVersion = nAgt.substring(verOffset+1);
if (browserName.toLowerCase()==browserName.toUpperCase()) {
browserName = navigator.appName;
}
}
// trim the fullVersion string at semicolon/space if present
if ((ix=fullVersion.indexOf(";"))!=-1)
fullVersion=fullVersion.substring(0,ix);
if ((ix=fullVersion.indexOf(" "))!=-1)
fullVersion=fullVersion.substring(0,ix);
majorVersion = parseInt(''+fullVersion,10);
if (isNaN(majorVersion)) {
fullVersion = ''+parseFloat(navigator.appVersion);
majorVersion = parseInt(navigator.appVersion,10);
}
document.write(''
+'Browser name = '+browserName+'<br>'
+'Full version = '+fullVersion+'<br>'
+'Major version = '+majorVersion+'<br>'
+'navigator.appName = '+navigator.appName+'<br>'
+'navigator.userAgent = '+navigator.userAgent+'<br>'
)
How to find the operating system details using JavaScript?
If you list all of window.navigator
's properties using
console.log(navigator);
PHP Laravel : How to get client browser/ Device?
First add the package to your composer:
{
"require": {
"hisorange/browser-detect": "2.*" // For laravel 5.* versions
"hisorange/browser-detect": "1.*" // For laravel 4.* versions
}
}
After the composer update/install add the service provider to your app.php:
'providers' => array(
// ...
'hisorange\BrowserDetect\Provider\BrowserDetectService',
// ...
)
Add the alias to the aliases in your app.php:
'aliases' => array(
// ...
'BrowserDetect' => 'hisorange\BrowserDetect\Facade\Parser',
)
You must use personal configurations, just publish the package's configuration files, (plugins.php also published with this)
php artisan vendor:publish
You can get result informations by simply call on the facade.
// You can always get the result object from the facade if you wish to operate with it.
BrowserDetect::detect(); // Will resolve and return with the 'browser.result' container.
// Calls are mirrored to the result object for easier use.
BrowserDetect::browserVersion(); // return '3.6' string.
// Supporting human readable formats.
BrowserDetect::browserName(); // return 'Firefox 3.6' string.
// Or can be objective.
BrowserDetect::browserFamily(); // return 'Firefox' string.
For details: https://github.com/hisorange/browser-detect
Related Topics
Does Java Have a Int.Tryparse That Doesn't Throw an Exception for Bad Data
Cannot Create Jdbc Driver of Class ' ' for Connect Url 'Null':I Do Not Understand This Exception
Java 8, Streams to Find the Duplicate Elements
Time Complexity of Java's Substring()
How to See the Source Code of the Sun Jdk
Use of Java [Interfaces/Abstract Classes]
Is There a Good Reason to Use "Printf" Instead of "Print" in Java
Unexpected Type Resulting from the Ternary Operator
What's the Default Value of Char
How to Get Current Working Directory in Java
In Java, What Are the Boolean "Order of Operations"
Should a "Static Final Logger" Be Declared in Upper-Case
Intellij Cannot Resolve Symbol on Import
How to Load/Reference a File as a File Instance from the Classpath