Re: server side user agent detection

From: Date: Tue, 31 Oct 2000 08:04:57 +0000
Subject: Re: server side user agent detection
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-22873@lists.php.net to get a copy of this message
Jan-Eric Duden wrote: > > I'd like to do server side user agent detection. That is to check the HTTP_USER_AGENT > variable, right? > > Does anybody have some nice and tested regex that check this string for IE 4.0 or NN 4.0 ? > What about other browsers? > Hi! I made once a little simple function for detection. Surely it's not the best solution, but you can start from this. <? function browser() { global $HTTP_USER_AGENT; if (ereg("^.*Linux.*$", $HTTP_USER_AGENT)) { return "linux_NN"; } elseif (ereg("^.*Win.*$", $HTTP_USER_AGENT)) { if (ereg("^.*MSIE 5\.[0-9].*$", $HTTP_USER_AGENT)) { return "win_IE5"; } elseif (ereg("^.*MSIE.*$", $HTTP_USER_AGENT)) { return "win_IE"; } elseif (ereg("^.*Mozilla.*$", $HTTP_USER_AGENT)) { return "win_NN"; } } elseif (ereg("^.*Macintosh.*$", $HTTP_USER_AGENT)) { return "mac_NN"; } elseif (ereg("^.*MSIE 5\.[0-9].*PowerPC.*$", $HTTP_USER_AGENT)) { return "mac_IE5"; } elseif (ereg("^.*MSIE 4\.[0-9].*PowerPC.*$", $HTTP_USER_AGENT)) { return "mac_IE4"; } else { return "other"; } } ?> Hope this helps! :) -- Pavel a.k.a. Papi

« previous php.general (#22873) next »