Languages :: PHP :: Detecting browser with PHP |
|||
| By: PHP newbee |
Date: 17/07/2003 00:00:00 |
Points: 125 | Status: Answered Quality : Excellent |
|
Hi all, I have a simple drop-down Javascript menu, that I would like to display in IE, but replace with a static menu in NN. I need to detect the browser using PHP. I am an ASP developer by nature, just getting into PHP, so please be quite elaborate with your answer as I'm new to this. I used the following to take a look at the results. <? $browser = get_browser(); echo $browser; ?> I understand that this may have issues with regard to proxy settings etc., but I have set the page not to cache and so far so good, it seems to be working, so that's not a problem either. I just need a way to look at the output from get_brower() and determine simply whether the browser is NN or IE, which clearly isn't as easy as I thought i.e. as in Javascript. Any help please!? |
|||
| By: Muuss | Date: 17/07/2003 00:36:00 | Type : Comment |
|
| $_SERVER['HTTP_USER_AGENT']; |
|||
| By: jfowlie | Date: 17/07/2003 00:37:00 | Type : Comment |
|
| Read this article: <A HREF="http://www.phpbuilder.com/columns/tim20000821.php3">http://www.phpbuilder.com/columns/tim20000821.php3</a> It was actually written for determining the browser and thus using the appropriate style sheet, but all the code you need for determining browser is on page 2: <A HREF="http://www.phpbuilder.com/columns/tim20000821.php3?page=2">http://www.phpbuilder.com/columns/tim20000821.php3?page=2</a> |
|||
| By: VGR | Date: 17/07/2003 04:38:00 | Type : Answer |
|
| yes, the user agent will give you basic information. personally, I "detect" IE/NS and Win/notWin using this (I don't need to detect MacIntosh, nor Opera , Mozilla Firebird, etc) $ua=getenv("HTTP_USER_AGENT"); $pos=strpos($ua,'('); $apres=''; if ($pos>0) { $avant=substr($ua,0,$pos); $apres=substr($ua,$pos+1); if (strpos($apres,')')>0) $apres=substr($apres,0,strpos($apres,')')); } else $avant=$ua; $notNS=(strpos($avant,'Mozilla')===false); if (!$notNS) $notNS=!(strpos($apres,'MSIE')===false); $sess_isNS=(!$notNS); $wd=getenv("WINDIR"); $sess_osWin=($wd<>''); session_register("sess_isNS"); session_register("sess_osWin"); |
|||
| By: noam_dz | Date: 18/07/2003 00:52:00 | Type : Comment |
|
| please have a look at <A HREF="http://sourceforge.net/projects/phpsniff/">http://sourceforge.net/projects/phpsniff/</a> <A HREF="http://il.php.net/function.get-browser">http://il.php.net/function.get-browser</a> hope they will help. |
|||
| By: PHP newbee | Date: 18/07/2003 01:18:00 | Type : Comment |
|
| Thanks for your help guys. I accepted VGR's answer since he gave a fuller example code-wise which I needed given that I'm a PHP rookie. However, I actually sorted this myself a while back but haven't been able to accept answers as zone alarm did something crazy to my cookie settings and I wasn't able to log into any sites correctly. Doh! Thanks for all ya help P |
|||
| By: VGR | Date: 18/07/2003 01:29:00 | Type : Comment |
|
| cool 8-) | |||
|
Do register to be able to answer |
|||
©2010 These pages are served without commercial sponsorship. (No popup ads, etc...). Bandwidth abuse increases hosting cost forcing sponsorship or shutdown. This server aggressively defends against automated copying for any reason including offline viewing, duplication, etc... Please respect this requirement and DO NOT RIP THIS SITE.
Please DO link to this page!








