faqts : Computers : Programming : Languages : PHP

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

29 of 45 people (64%) answered Yes
Recently 5 of 10 people (50%) answered Yes

Entry

How to do Browser, JavaScript, and CSS detection using PHP?

Feb 29th, 2008 10:12
dman, Philip Olson, John S., Ben Udall, http://www.ttnr.org


The simplest way to find a users information is by viewing their 
HTTP_USER_AGENT and to do this simply print it :
  <?php
    print $HTTP_USER_AGENT;
  ?>
For a list of "predefined variables" such as the above, go here :
  http://www.php.net/manual/language.variables.predefined.php
  http://hoohoo.ncsa.uiuc.edu/cgi/env.html
PHP has a built in browser detection function called get_browser, you 
can read about it here :
  http://www.php.net/manual/function.get-browser.php
In the user comments comments you'll see links to user created 
functions/scripts that do such detections.  For an interesting article 
on this subject, have a look at :
  http://phpbuilder.com/columns/tim20000821.php3
And again, pay attention to the user comments.  This article explains 
how to use browser detection to create a browser friendly CSS.  
The "main" CSS guide out there is :
  http://webreview.com/wr/pub/guides/style/mastergrid.html
And you can find more CSS browser specific Information here :
  http://dmoz.org/Computers/Programming/Internet/CSS/Compatibility_Info/
Now regarding browser specific needs, such as with JavaScript, you'll 
want to know there Browser Object Models.  Good place to start :
  Both     : http://www.webreference.com/js/column6/
  Netscape : http://devedge.netscape.com/tech/dom/ 
  IE       : http://msdn.microsoft.com/workshop/cframe.htm?/
             workshop/author/default.asp
BTW, the IE link is on two lines, it doesn't fit on one here.