Recently, I am going to make a small upgrade for my website so that users can display templates suitable for mobile phones during QR code scanning [ThinkPHP3.0 is used]. the code is for reference by others, let me start with a rough idea of two simple steps: the system version number.
Recently, I am going to make a small upgrade for my website so that users can display templates suitable for display on the mobile phone terminal when scanning the QR code on their mobile phone [ThinkPHP3.0 is used]. the code is for reference by others.
Let me start with a rough idea of two simple steps:
The general version number, the browser version number, and the version number (only mobile terminal information is contained in the array in the pasted code, so you only need to judge whether it is a value in the array ).
Determine whether a visitor is a mobile phone, tablet, or other mobile terminal based on the values in the array, if yes, define the project path and NAME as your mobile phone template, for example, define ('app _ name', 'mobi ');
Define ('app _ path', './mobi /');
Add comments as much as possible for the following code:
- // Determine whether the mobile phone belongs
- // The code looks a lot. In fact, the array looks a lot messy and should not be intimidated by the surface phenomenon!
- Function is_mobile (){
- $ User_agent = $ _ SERVER ['http _ USER_AGENT '];
-
- $ Mobile_agents = Array ("240x320", "acer", "ACO on", "acs-", "abacho", "ahong", "airness", "alcatel ", "amoi", "android", "anywhereyougo.com", "applewebkit/525", "applewebkit/532", "asus", "audio", "au-mic ", "avantogo", "becker", "benq", "bilbo", "bird", "blackberry", "blazer", "bleu", "cdm -", "compal", "coolpad", "danger", "dbtel", "dopod", "elaine", "eric", "etouch", "fly ", "fly _", "fly-", "go. web "," goodaccess "," gradiente "," grundig "," haier "," hedy "," hitachi "," htc "," huawei "," Huchison ", "inno", "ipad", "ipaq", "ipod", "jbrowser", "kddi", "kgt", "kwc", "lenovo", "lg ", "lg2", "lg3", "lg4", "lg5", "lg7", "lg8", "lg9", "lg-", "lge -", "lge9", "longcos", "maemo", "mercator", "meridian", "micromax", "midp", "mini", "mitsu", "mmm ", "mmp", "mobi", "mot-", "moto", "nec-", "netfront", "newgen", "nexian", "nf-browser ", "nintendo", "nitro", "nokia", "nook", "novarra", "obigo", "palm", "panasonic", "pantech", "philips ", "phone", "pg-", "playstation", "pocket", "pt-", "qc-", "qtek", "rover", "sagem ", "sama", "samu", "sanyo", "samsung", "sch-", "scooter", "sec-", "sendo", "sgh -", "sharp", "siemens", "sie-", "softbank", "sony", "spice", "sprint", "spv", "symbian ", "tablet", "talkabout", "tcl-", "teleca", "telit", "tianyu", "tim-", "toshba", "tsm ", "up. browser "," utec "," utstar "," verykool "," virgin "," vk-"," voda "," voxtel "," vx "," wap ", "wellco", "wig browser", "wii", "windows ce", "wireless", "xda", "xde", "zte ");
- $ Is_mobile = false;
- Foreach ($ mobile_agents as $ device) {// Here, the value is traversed to find whether the above string has appeared
- If (stristr ($ user_agent, $ device) {// stristr to check whether the visitor information is in the preceding array. if the information does not exist, it is PC.
- $ Is_mobile = true;
- Break;
- }
- }
- Return $ is_mobile;
- }
- Define ('think _ path', './CORE /');
- If (is_mobile () {// jump to the wap Group
- Echo 'you have accessed the mobile phone and jumped to the mobile phone end ';
- Define ('app _ name', 'mobi ');
- Define ('app _ path', './mobi /');
- } Else {
- Echo 'You accessed from the PC ';
- Define ('app _ name', 'home ');
- Define ('app _ path', './Home /');
- }
- Define ('app _ debug', false );
- Require THINK_PATH. 'core. php ';