note 51453 deleted from function.get-browser by bjori
| From: | bjori@php.net | Date: | Mon, 09 Oct 2006 11:00:53 +0000 |
| Subject: | note 51453 deleted from function.get-browser by bjori | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-118258@lists.php.net to get a copy of this message | ||
Note Submitter: :: TomkOx ::
----
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. ;)