Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP Laravel : How to get client browser/ Device?

I'm building a laravel application where I want to keep track of client browser details such as browser name. How do I do it using Laravel ?

public function postUser(Request $request)
    {        
            $user = new User();                                 
            $user->name = $request->Input(['name']);           
            $device=   $request->header('User-Agent');
            dd($device);
            $user->save();            
            return redirect('userSavePage');          
    }

I have used this $device= $request->header('User-Agent'); But while I dd() the output I get something Like this:

"Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.102 Safari/537.36"

How do I get actual browser details?

like image 485
Hola Avatar asked May 18 '16 07:05

Hola


People also ask

How to get browser details in Laravel?

You can also find out the browser version by passing the result of Agent::browser() to the version() method like so: 1$browser = Agent::browser(); 2$version = Agent::version($browser);

How do I get a user device in Laravel?

Route::get('browser', function () { //create new agent instance $agent = new Jenssegers\Agent\Agent(); //check if agent is robot if ($agent->isRobot()) { return $agent->robot(); } //if agent is not robot then get agent browser and platform like Chrome in Linux $agent = $agent->browser() . " in " .

How to detect user agent in Laravel?

This is a Laravel package that utilizes the Mobile Detect PHP Class under the hood: Mobile_Detect is a lightweight PHP class for detecting mobile devices (including tablets). It uses the User-Agent string combined with specific HTTP headers to detect the mobile environment.

How do I find my MAC address in Laravel?

To get the MAC address, pass the parameter 'getmac' which returns the MAC address of the client. 'getmac' is a CMD command to get the MAC address. To get the MAC address, we use exec() function. $macAddr = exec('getmac');


1 Answers

I ended using the faster, and simpler way:

$request->header('User-Agent');

Hope it helps someone!

like image 186
dahngeek Avatar answered Sep 19 '22 21:09

dahngeek