Location: PHPKode > scripts > Sniff Response 4b > sniff-response-4b/SniffResponse_User_Documentation.html
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
	<META HTTP-EQUIV="CONTENT-TYPE" CONTENT="text/html; charset=windows-1252">
	<TITLE></TITLE>
	<META NAME="GENERATOR" CONTENT="OpenOffice.org 1.9.122  (Win32)">
	<META NAME="AUTHOR" CONTENT="Grant Paton-Simpson">
	<META NAME="CREATED" CONTENT="20050818;11394900">
	<META NAME="CHANGEDBY" CONTENT="Grant Paton-Simpson">
	<META NAME="CHANGED" CONTENT="20050818;13142468">
	<STYLE>
	<!--
		@page { size: 21cm 29.7cm; margin: 2cm }
		P { margin-bottom: 0.21cm }
		H1 { margin-bottom: 0.21cm }
		H1.western { font-family: "Arial", sans-serif; font-size: 16pt }
		H1.cjk { font-family: "Lucida Sans Unicode"; font-size: 16pt }
		H1.ctl { font-family: "Tahoma"; font-size: 16pt }
		H2 { margin-bottom: 0.21cm }
		H2.western { font-family: "Arial", sans-serif; font-size: 14pt; font-style: italic }
		H2.cjk { font-size: 14pt; font-style: italic }
		H2.ctl { font-size: 14pt; font-style: italic }
	-->
	</STYLE>
</HEAD>
<BODY LANG="en-US" DIR="LTR">
<H1 CLASS="western">SniffResponse 0.9.0</H1>
<P>SniffResponse (PHP5)</P>
<P>SniffResponse4 (PHP4)</P>
<P STYLE="margin-bottom: 0cm"><BR>
</P>
<DIV ID="Table of Contents1" DIR="LTR">
	<DIV ID="Table of Contents1_Head" DIR="LTR">
		<P STYLE="margin-top: 0.42cm; page-break-after: avoid"><FONT FACE="Arial, sans-serif"><FONT SIZE=4 STYLE="font-size: 16pt"><B>Table
		of Contents</B></FONT></FONT></P>
	</DIV>
	<P STYLE="margin-bottom: 0cm">SniffResponse 0.9.0	1</P>
	<P STYLE="margin-left: 0.5cm; margin-bottom: 0cm">Example use of
	SniffResponse (or SniffResponse4 in PHP4)	2</P>
	<P STYLE="margin-left: 0.5cm; margin-bottom: 0cm">Why SniffResponse
	was created	2</P>
	<P STYLE="margin-left: 0.5cm; margin-bottom: 0cm">Why not use
	get_browser( )?	3</P>
	<P STYLE="margin-left: 0.5cm; margin-bottom: 0cm">Future
	development	3</P>
</DIV>
<P STYLE="margin-bottom: 0cm"><BR>
</P>
<P STYLE="margin-bottom: 0cm"><BR>
</P>
<H2 CLASS="western" STYLE="page-break-before: always">Example use of
SniffResponse (or SniffResponse4 in PHP4)</H2>
<P><BR><BR>
</P>
<P>require_once('class.SniffResponse.php');</P>
<P>$obj_sniff = new SniffResponse('browser_not_ok.php');</P>
<P><BR><BR>
</P>
<P>That was it!  Now if the browser is substandard, the
'browser_not_ok.php' script will run instead of the normal page.  Tip
- Commonly the 'browser_not_ok.php' script ends with the exit command
to ensure that the remainder of the normal page doesn't get appended
onto the end of the special warning page.</P>
<P>Separate scripts can be specified depending on the browser
standard e.g. not_ok, just_ok, modern, or unknown.  In the case of
the latter, it might make sense to add a JavaScript sniffer as a
final line of defence.</P>
<P>The class has default levels set for just_ok etc but these can be
overriden through passed arguments.  For example: 
</P>
<P>$obj_sniff = new SniffResponse('browser_not_ok.php','','','',5);
//IE for windows is considered OK if 5 or higher, not the default of
5.5.</P>
<P>There are also some useful methods &ndash; e.g.</P>
<P>$obj_sniff-&gt;getBrowser(); //might return Firefox.</P>
<P>$obj_sniff-&gt;getVersion(); //might return 1.0.4</P>
<P>$obj_sniff-&gt;getBrowserStandard(); /*might return 'unknown'
(SniffResponse::UNKNOWN for 	those with PHP5 and support for class
constants).*/</P>
<H2 CLASS="western">Why SniffResponse was created</H2>
<OL>
	<LI><P STYLE="margin-top: 0.2cm; margin-bottom: 0cm">My <B>CSS-driven,
	standards-compliant pages were being mangled by old browsers</B>.</P>
	<LI><P STYLE="margin-top: 0.2cm; margin-bottom: 0cm">I needed a
	<B>server-side</B> browser sniffer &ndash; client-side browser
	sniffing can be disabled at the client end if JavaScript is
	disabled.  Server-side browser sniffing also simplifies the HTML
	sent to browsers.  <BR><BR>(Of course, JavaScript can be used
	alongside server-side sniffing.  This might be desirable in cases
	where a HTTP_USER_AGENT string is not supplied &ndash; perhaps
	because of a GhostSurf type program or because of AOL proxy server
	issues).</P>
	<LI><P STYLE="margin-top: 0.2cm; margin-bottom: 0cm">I wanted to be
	able to <B>group my responses</B> to browsers according to standards
	e.g. to respond to all archaic browsers the same &ndash; perhaps by
	serving them a script inviting them to upgrade using the supplied
	links.  It is not efficient to have to check off the browser against
	your own list each time you sniff for them.  The class should do
	this work for you.</P>
	<LI><P STYLE="margin-top: 0.2cm; margin-bottom: 0cm">There needed to
	be a <B>simple way of tweaking the thresholds</B> for browsers e.g.
	IE 5.0 might be OK for some of your sites but not others.  In which
	case the minimum level might be raised to 5.5 by changing one
	argument.</P>
	<LI><P STYLE="margin-top: 0.2cm; margin-bottom: 0cm">I needed
	<B>flexibility in how I responded</B>.  In some cases, the response
	if a substandard browser is encountered is to serve up a special
	script.  In other cases what is needed is a return value indicating
	the browser standard.  The developer can respond in a more flexible
	way.</P>
</OL>
<H2 CLASS="western">Why not use get_browser( )?</H2>
<P STYLE="margin-bottom: 0cm">Originally, SniffResponse was driven by
get_browser but I decided to rely directly on HTTP_USER_AGENT after
some problems with getting web hosts to successfully support
browscap.ini.  Additionally, browscap.ini is a large file to parse on
a regular basis.</P>
<P STYLE="margin-bottom: 0cm"><BR>
</P>
<H2 CLASS="western">Future development</H2>
<P STYLE="margin-bottom: 0cm">Extend the list of robots and browsers
&ndash; the code has been written to make this easy.  In the future
the default thresholds for ok and modern will be raised.</P>
<P STYLE="margin-bottom: 0cm"><BR>
</P>
<P STYLE="margin-bottom: 0cm"><BR>
</P>
<P STYLE="margin-bottom: 0cm"><BR>
</P>
<P STYLE="margin-bottom: 0cm"><BR>
</P>
</BODY>
</HTML>
Return current item: Sniff Response 4b