In some cases, we need to determine whether the HTTP request is from the phone or the computer side, the key is to obtain user-agent information, screening and judgment can be.
The core classes are as follows:
public static Boolean IsMobileDevice (String requestheader) { /** * android: All Android devices * Mac OS: iphone ipad * Windows Phone:nokia such as Windows system phone */ string[] Devicearray = new string[]{"Android", "Mac OS", " Windows Phone "}; if (Requestheader = = null) return false; Requestheader = Requestheader.tolowercase (); for (int i=0;i<devicearray.length;i++) { if (Requestheader.indexof (Devicearray[i]) >0) { return true; } } return false;
Get the HTTP header information in the controller as follows:
String Requestheader = Request.getheader ("user-agent"); if (Judgerequestdeviceutil.ismobiledevice (Requestheader)) { logger.debug ("Use mobile browser"); } else{ logger.debug ("Use Web browser"); }
functionis_mobile_visit () {//If you have http_x_wap_profile, it must be a mobile device . if(isset($_server[' Http_x_wap_profile '])) { return true; } //if the VIA message contains a WAP, it must be a mobile device, and some service providers block that information if(isset($_server[' Http_via '])) { //not found for flase, otherwise true return Stristr($_server[' Http_via '], "WAP")?true:false; } //brain Residue method, determine the mobile phone to send the client logo, compatibility needs to be improved if(isset($_server[' Http_user_agent '])) { $clientkeywords=Array(' Nokia ', ' Sony ', ' Ericsson ', ' mot ', ' Samsung ', ' HTC ', ' SGH ', ' lg ', ' sharp ', ' sie-', ' Philips ' , ' Panasonic ', ' Alcatel ', ' Lenovo ', ' iphone ', ' ipod ', ' blackberry ', ' Meizu ', ' Android ', ' NetFront ', ' Symbian ', ' UCWeb ', ' windowsce ', ' palm ', ' Operamini ', ' Operamobi ', ' Openwave ', ' nexusone ', ' CLDC ', ' mid P ', ' wap ', ' mobile ' ); //find keywords for your phone's browser from Http_user_agent if(Preg_match("/(" .implode(' | ',$clientkeywords) . ")/I",Strtolower($_server[' Http_user_agent ']))) { return true; } } //protocol law, because there may be inaccuracies, put to the final Judgment if(isset($_server[' Http_accept '])) { //If only WML is supported and HTML is not supported that must be mobile device//If WML and HTML are supported but WML is mobile device before HTML if((Strpos($_server[' Http_accept '], ' vnd.wap.wml ')!==false) && (Strpos($_server[' Http_accept '], ' text/html ') = = =false|| (Strpos($_server[' Http_accept '], ' vnd.wap.wml ') <Strpos($_server[' Http_accept '], ' text/html ')))) { return true; } } return false;}
Determine if the HTTP request originated from the mobile phone, or if there is a computer-initiated