SERVER-SIDE DETECTION


This section contains server-side examples that detect the Pocket PC operating system. The code snippets check to see whether the request comes from a browser on the Pocket PC operating system. If so, the code snippet redirects to a success.html page; if the request does not come from a Pocket PC device, the code will display that the request does not come from a Pocket PC device.

The code detects the Pocket PC by searching for the string "PPC" in the HTTP_USER_AGENT field sent by the browser along with the request. This technique can be used to redirect the user to different versions of a Flash movie depending on what device or browser the request is made from.

Note that only the first code example is documented, but all the code examples follow the exact same steps.

Macromedia ColdFusion

This ColdFusion code detects whether a request came from Pocket Internet Explorer running on a Pocket PC device.

 <! -          Get the user agent from the request sent by the browser.   ->  <cfset userAgent="#CGI.HTTP_USER_AGENT#">  <cfset isPocketPc = false>  <! -          Check to see that the user agent is not blank, and if it contains the string  graphics/ccc.gif"PPC".  If it does, that means the request came from a Pocket PC, otherwise, the request did not  graphics/ccc.gifcome from a Pocket PC.   ->  <cfif (userAgent IS NOT "") AND (find("PPC", #userAgent#) GT 0)>           <cfset isPocketPc = true>  </cfif>  <cfif isPocketPc>           <cflocation url="success.html">  <cfelse>           You are <b>not</b> connecting with a Pocket PC device. </cfif> 

PHP

This PHP code detects whether a request came from Pocket Internet Explorer running on a Pocket PC device.

 <?php         $headers = getallheaders();         $userAgent = $headers["User-Agent"];         $isPocketPc = false;         if($userAgent != null && strpos($userAgent, "PPC"))         {                 $isPocketPc = true;         }         if($isPocketPc)         {                 header ("Location: success.html");                 exit;         }         else         {                 out.print("You are <b>not</b> connecting with a Pocket PC device.");         }  ?> 

JSP

This JSP code detects whether a request came from Pocket Internet Explorer running on a Pocket PC device.

 <%         String userAgent = request.getHeader("User-Agent");         boolean isPocketPc = false;         if(userAgent != null && userAgent.indexOf("PPC" , 0) > 0)         {                 isPocketPc = true;         }         if(isPocketPc)         {                 response.sendRedirect("success.html");                 return;         }         else         {                 out.print("You are <b>not</b> connecting with a Pocket PC device.");         }  %> 

ASP

This ASP code detects whether a request came from Pocket Internet Explorer running on a Pocket PC device.

 <%         userAgent = Request.ServerVariables("HTTP_USER_AGENT")         isPocketPc = false         if(userAgent <> "" AND (InStr(userAgent, "PPC") > 0)) then                 isPocketPc = true         end if         if isPocketPc then                 response.redirect("success.html")         else                 response.write("You are <b>not</b> connecting with a Pocket PC device.")         end if  %> 


Macromedia Flash Enabled. Flash Design and Development for Devices
Macromedia Flash Enabled. Flash Design and Development for Devices
ISBN: 735711771
EAN: N/A
Year: 2002
Pages: 178

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net