thinkphp how to differentiate between mobile and PC via a portal file

Source: Internet
Author: User
This article mainly describes the thinkphp through a portal file to distinguish between mobile and PC-side methods, the need for friends to refer to the bar

Not much nonsense to say, directly to everyone to paste the code, the specific code is as follows:

<?php//detects the PHP environment if (Version_compare (php_version, ' 5.3.0 ', ' < ') die (' Require PHP > 5.3.0! '); /Open debug mode suggest the development phase to open the deployment phase Comment or set to Falsedefine (' App_debug ', True);d efine (' Multi_module ', false);//Get the directory where the current file is located define (' Dksite_tsdir ', dirname (__file__));//define the application directory define (' App_path ', Dksite_tsdir. '  /application/');//function is_mobile () {$user _agent = $_server[' http_user_agent ']; $mobile _agents = Array ("240x320", "Acer", "Acoon", "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 "," Hutchison "," 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-"," Toshiba "," 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 once to find out if any of the above strings have occurred if (Stristr ($user _agent, $device)) {//stristr Find the guest information       Whether in the above array, the non-existent is the PC side.       $is _mobile = true;     Break }} return $is _mobile;   }//Judge if (Is_mobile ()) {echo ' You are currently on: Mobile side '; Mobile phone-side module define (' Bind_module ', ' Mobile ');}  else{Echo ' You are currently on: PC side '; // PC-Side front-end module define (' Bind_module ', ' Home '); }//introduced thinkphp entry file require DirName (__file__). ' /thinkphp/thinkphp.php ';

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.