note 51453 added to function.get-browser
| From: | ::TomkOx:: at osu1 dot php dot net | Date: | Thu, 31 Mar 2005 06:12:39 +0000 |
| Subject: | note 51453 added to function.get-browser | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-87233@lists.php.net to get a copy of this message | ||
It is not good to use function: strpos() in detecting browser or OS by HTTP_USER_AGENT. Better is to
use function strstr() becouse some strings returned by HTTP_USER_AGENT have 'needed
information' at 1st (0) position of the string. Function strpos() 'will not find' for
eg. signature of Opera on OSX. I think it's better to use like this (example):
<?
// ...
Class SomeDetectoriumClass {
// ...
// here starts this method (function):
function aboutNetGuest() {
$curos=strtolower($_SERVER['HTTP_USER_AGENT']);
$uip=$_SERVER['REMOTE_ADDR'];
$uht=gethostbyaddr($_SERVER['REMOTE_ADDR']);
if (strstr($curos,"mac")) {
$uos="MacOS";
} else if (strstr($curos,"linux")) {
$uos="Linux";
} else if (strstr($curos,"win")) {
$uos="Windows";
} else if (strstr($curos,"bsd")) {
$uos="BSD";
} else if (strstr($curos,"qnx")) {
$uos="QNX";
} else if (strstr($curos,"sun")) {
$uos="SunOS";
} else if (strstr($curos,"solaris")) {
$uos="Solaris";
} else if (strstr($curos,"irix")) {
$uos="IRIX";
} else if (strstr($curos,"aix")) {
$uos="AIX";
} else if (strstr($curos,"unix")) {
$uos="Unix";
} else if (strstr($curos,"amiga")) {
$uos="Amiga";
} else if (strstr($curos,"os/2")) {
$uos="OS/2";
} else if (strstr($curos,"beos")) {
$uos="BeOS";
} else { $uos="[?]EgzoticalOS";
}
if (strstr($curos,"gecko")) {
if (strstr($curos,"safari")) {
$bos="Safari";
} else if (strstr($curos,"camino")) {
$bos="Camino";
} else if (strstr($curos,"firefox")) {
$bos="Firefox";
} else if (strstr($curos,"netscape")) {
$bos="Netscape";
} else { $bos="Mozilla";
}
} else if (strstr($curos,"opera")) {
$bos="Opera";
} else if (strstr($curos,"msie")) {
$bos="Internet Exploder";
} else if (strstr($curos,"voyager")) {
$bos="Voyager";
} else if (strstr($curos,"lynx")) {
$bos="Lynx";
} else { $bos="[?]EgzoticalBrowser";
}
return array ($uos,$bos,$uip,$uht);
} // - Class Closer;
// ...
?>
Regards from Poland, TomkOx. ;)
----
Manual Page -- http://www.php.net/manual/en/function.get-browser.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+51453
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+51453&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+51453&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+51453&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+51453&report=yes&reason=useless
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+51453&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+51453&report=yes
Search -- http://master.php.net/manage/user-notes.php