Page 1 of 1

problem with get_browser()

Posted: Fri Mar 14, 2003 11:55 am
by JensP
Hello!

I suppose the function get_browser() doesn't work correctly.
The following example (out of the PHP documentation) delivers no valid result:

<?php
function list_array ($array) {
while (list ($key, $value) = each ($array)) {
$str .= "<b>$key:</b> $value<br>\n";
}
return $str;
}
echo "$HTTP_USER_AGENT<hr>\n";
$browser = get_browser();
echo list_array ((array) $browser);
?>


Just as the first example, this one doesnt' work either:

<?
$ua = get_browser ();
echo "Browser: $ua->browser";
?>

It would be very nice if someone told me what I'm doing wrong!
(PHP Version: 4.2.2)

greets
Jens

Posted: Fri Mar 14, 2003 12:05 pm
by volka
does the browscap parameter in your php.in point to a valid browscap.ini?
what does

Code: Select all

<?php echo $HTTP_SERVER_VARS['HTTP_USER_AGENT']; ?>
print? is there a corresponding entry in browscap.ini?

Posted: Fri Mar 14, 2003 12:13 pm
by JensP
Hello Vola!


<?php echo $HTTP_SERVER_VARS['HTTP_USER_AGENT']; ?>

works correct, it prints e.g. something like this:

"Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0) "

I don't know how the browscap.ini looks like, because it is on our providers server.

greets

JEns

Posted: Fri Mar 14, 2003 12:58 pm
by volka
then try

Code: Select all

<?php phpinfo(); ?>
and/or

Code: Select all

<?php
$bc = ini_get('browscap');
if ($bc !== '')
{
		header('Content-type: text/plain');
		readfile($bc);
}
else
	echo 'no browscap.ini';
?>
if there is no browscap.ini you might ask the administrator/provider or install one for yourself and set the parameter within your script

Code: Select all

<?php
init_set('browscap', $pathToFile);
?>
before calling get_browser()

Posted: Tue Mar 18, 2003 10:55 am
by JensP
Hello volka!

You were right, the problem was the missing 'browscap' entry in php.ini.

I contact my Webhoster and he told me that they do not provide this feature because it is not free of bugs (http://bugs.php.net/bug.php?id=19649) :(

Thank you anyway...

JEns

Posted: Tue Mar 18, 2003 1:39 pm
by volka
Status: Closed
Category: Reproducible crash
Version: 4.3.0-dev
...
This bug has been fixed in CVS.

In case this was a PHP problem, snapshots of the sources are packaged
every three hours; this change will be in the next snapshot.
I can't reproduce any of these errors on PHP 4.3.1 (neither w2k, nor gentoo-linux)