visitor (0 QPoints)
  • FR
  • EN
  • NL
  • DE
  • ES
316 experts, 1194 registered users, 1659 questions already answered
European Experts Exchange, the very best site for high-quality IT solutions

New Improved Search!

 


05/10/2011 1h30 : Steve Jobs is dead, the father of Apple ][ is gone, we are all orphaned.

Languages :: PHP :: Detecting browser with PHP


By: PHP newbee U.S.A.  Date: 17/07/2003 00:00:00  English  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 English  Type : Comment
$_SERVER['HTTP_USER_AGENT'];


By: jfowlie Date: 17/07/2003 00:37:00 English  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 English  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 English  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 English  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 English  Type : Comment
cool 8-)

Do register to be able to answer

EContact
browser fav
page generated in 293.917890 milliseconds

Why Google AdSense ads ?

compteur
 Ranking-Hits PageRank for this page