开发者

How to get the name of browser?

I hav开发者_高级运维e 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


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());


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

 <?php

    $browser = get_browser();

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

    ?> 
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜