Linto P D
Linto P D

Reputation: 9165

How to get the name of browser?

I have tried $_SERVER['HTTP_USER_AGENT'], but we didn't get the exact name.

Then i have tried the following code

$browser = get_browser(null, true);
print_r($browser);

Firstly it shows warning.then i have enable it in the .ini file.

After that it dosen't display anything.

Is there any other solution to know the name

Upvotes: 0

Views: 1767

Answers (2)

Thomas Schuster
Thomas Schuster

Reputation: 320

I think the warning you are referring to is "Warning: get_browser() [function.get-browser]: browscap ini directive not set". This means you have to configure the location of browser-index-file.

  • Download the file php_browscap.ini (as a new user i am not allowed to post the hyperlink here..., i am only allowed to post one hyperlink)
  • Link to it in your php.ini

Or you could use http://github.com/garetjax/phpbrowscap. Then you do not have to tinker with php.ini:

<?php

require_once 'browscap/Browscap.php';

$browscap = new Browscap(sys_get_temp_dir());
var_dump($browscap->getBrowser());

Upvotes: 2

PHP
PHP

Reputation: 1709

I think approach is fine... anywayz just try this ....

 <?php

    $browser = get_browser();

    echo 'Browser: ' . $browser->browser . "<br />\n";
    echo 'Version: ' . $browser->version;

    ?> 

Upvotes: 2

Related Questions