您好,登錄后才能下訂單哦!
這篇文章主要介紹“Thinkphp通過一個入口文件怎么區分移動端和PC端”,在日常操作中,相信很多人在Thinkphp通過一個入口文件怎么區分移動端和PC端問題上存在疑惑,小編查閱了各式資料,整理出簡單好用的操作方法,希望對大家解答”Thinkphp通過一個入口文件怎么區分移動端和PC端”的疑惑有所幫助!接下來,請跟著小編一起來學習吧!
廢話不多說了,直接給大家貼代碼了,具體代碼如下所示:
<?php // 檢測PHP環境 if(version_compare(PHP_VERSION,'5.3.0','<')) die('require PHP > 5.3.0 !'); // 開啟調試模式 建議開發階段開啟 部署階段注釋或者設為false define('APP_DEBUG',True); define('MULTI_MODULE', false); // 獲取當前文件所在的目錄 define('DKSITE_TSDIR', dirname(__FILE__)); // 定義應用目錄 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) {//這里把值遍歷一遍,用于查找是否有上述字符串出現過 if (stristr($user_agent, $device)) { //stristr 查找訪客端信息是否在上述數組中,不存在即為PC端。 $is_mobile = true; break; } } return $is_mobile; } //判斷 if(is_mobile()){ echo '您當前是在:手機端'; // 手機端模塊 define('BIND_MODULE','Mobile'); }else{ echo '您當前是在:pc端'; // pc端前臺模塊 define('BIND_MODULE','Home'); } // 引入ThinkPHP入口文件 require dirname(__FILE__).'/ThinkPHP/ThinkPHP.php';
到此,關于“Thinkphp通過一個入口文件怎么區分移動端和PC端”的學習就結束了,希望能夠解決大家的疑惑。理論與實踐的搭配能更好的幫助大家學習,快去試試吧!若想繼續學習更多相關知識,請繼續關注億速云網站,小編會繼續努力為大家帶來更多實用的文章!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。