Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get user agent in PHP

Tags:

php

user-agent

I'm using this JS code to know what browser is user using for.

<script>   document.write(navigator.appName); </script> 

And I want to get this navigator.appName to php code to use it like this:

if ($appName == "Internet Explorer") {   // blabla } 

How can I do it?

like image 750
Olga Budnik Avatar asked Apr 20 '12 09:04

Olga Budnik


People also ask

How do I access user agent?

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.

How can I get browser information in PHP?

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.

How can I get user agent in laravel 8?

In this snippet, we'll see how to get user-agent from user request in laravel. $agent = $request->header('user-agent'); $agent = request()->header('user-agent'); $agent = Request::header('user-agent'); All of these code snippet return the User-agent in Laravel.

What is $_ server Http_user_agent?

The variable we are interested in right now is $_SERVER['HTTP_USER_AGENT'] . Note: $_SERVER is a special reserved PHP variable that contains all web server information. It is known as a superglobal. See the related manual page on superglobals for more information.


1 Answers

Use the native PHP $_SERVER['HTTP_USER_AGENT'] variable instead.

like image 151
noli Avatar answered Sep 18 '22 15:09

noli