0

From the manuals I am running a simple code to fetch browser info using get_browser() method.

Code in the manuals -

code_in_manuals

Code I am running(almost same/i tried by removing echo "<pre>"; but no effect) -

<?php
echo $_SERVER['HTTP_USER_AGENT'] . "\n\n";

$browser = get_browser(null, true);
echo "<pre>";
print_r($browser);
?>

This is the error/illegal characters I am getting at browser_name_regex -

get_browser_error

I also tried this UTF 8 encoding for characters, but problem still persist.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Test browser</title>
</head>

<body>
<?php
echo $_SERVER['HTTP_USER_AGENT'] . "\n\n";

$browser = get_browser(null, true);
echo "<pre>";
print_r($browser);
?>
</body>
</html>

Let me know what I am doing wrong and where to look for the solution?

One thing more to ask, in the same doc -

Attempts to determine the capabilities of the user's browser, by looking up the browser's information in the browscap.ini file.

Where do I find this browscap.ini in my system I am using Windows 7...although I am not very sure if it is related with this problem or not.

swapnesh
  • 26,318
  • 22
  • 94
  • 126
  • If you want to extract Browser Name then you can only use `echo $_SERVER['HTTP_USER_AGENT'];`. – Smile May 10 '13 at 05:00
  • @NullVoid thx bro I already know that ..but it is not what i was looking for...I am looking for the CURE not for the PREVENTION :) – swapnesh May 10 '13 at 05:03

2 Answers2

0

As you told that you found browscap.in file in your given path then specify that absolute path C:\xampp\php\extras\browscap.ini in your php.ini file like

I have in my local setup (php.ini), actually I have generated browscap file from other function and then pasted it in file and then found correct output.

[browscap]
;browscap = extra/browscap.ini
browscap = D:\ZendServer\etc\browscap.ini

you can specify your absolute path like

[browscap]
;browscap = extra/browscap.ini
browscap = C:\xampp\php\extras\browscap.ini

and code to check

echo $_SERVER['HTTP_USER_AGENT'] . "\n\n";

$browser = get_browser(null, true);
echo "<pre>";print_r($browser);die;
Smile
  • 2,770
  • 4
  • 35
  • 57
  • bro if thr is mismatching in file then NO DATA should be reflected ..but I am getting the data..ONLY problem in browser_name_regex ....rest ALL working fine as u can chk in screenshot – swapnesh May 10 '13 at 05:39
  • Then there should be some other issue because I am getting perfect infor without issue of character encoding. – Smile May 10 '13 at 05:41
  • You can try with this `header('Content-Type: text/html; charset=utf-8'); ` – Smile May 10 '13 at 05:43
0

The same question has been asked at PHP - get_browser() results

Based on the information there and the information found at https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=612364 which explains the bug more throughly, i've created some lines of code which solves the problem.

I've posted my answer both here and there.

Code:

if (function_exists('get_browser') && ini_get('browscap')) {
    $browser_info = get_browser(null, true);
    if (function_exists('mb_convert_encoding')) $browser_info['browser_name_regex'] = mb_convert_encoding($browser_info['browser_name_regex'], "UTF-8", "ISO-8859-1");
    print_r($browser_info);
}
Community
  • 1
  • 1