溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

Thinkphp通過一個入口文件怎么區(qū)分移動端和PC端

發(fā)布時間:2021-06-29 14:25:24 來源:億速云 閱讀:198 作者:chen 欄目:開發(fā)技術(shù)

這篇文章主要介紹“Thinkphp通過一個入口文件怎么區(qū)分移動端和PC端”,在日常操作中,相信很多人在Thinkphp通過一個入口文件怎么區(qū)分移動端和PC端問題上存在疑惑,小編查閱了各式資料,整理出簡單好用的操作方法,希望對大家解答”Thinkphp通過一個入口文件怎么區(qū)分移動端和PC端”的疑惑有所幫助!接下來,請跟著小編一起來學(xué)習(xí)吧!

廢話不多說了,直接給大家貼代碼了,具體代碼如下所示:

<?php
// 檢測PHP環(huán)境
if(version_compare(PHP_VERSION,'5.3.0','<')) die('require PHP > 5.3.0 !');
// 開啟調(diào)試模式 建議開發(fā)階段開啟 部署階段注釋或者設(shè)為false
define('APP_DEBUG',True);
define('MULTI_MODULE', false);
// 獲取當(dāng)前文件所在的目錄
define('DKSITE_TSDIR', dirname(__FILE__));
// 定義應(yīng)用目錄
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) {//這里把值遍歷一遍,用于查找是否有上述字符串出現(xiàn)過 
    if (stristr($user_agent, $device)) { //stristr 查找訪客端信息是否在上述數(shù)組中,不存在即為PC端。 
      $is_mobile = true; 
      break; 
    } 
  } 
  return $is_mobile; 
}
//判斷
if(is_mobile()){
 echo '您當(dāng)前是在:手機端'; 
  // 手機端模塊
 define('BIND_MODULE','Mobile');
}else{ 
 echo '您當(dāng)前是在:pc端';
  // pc端前臺模塊
 define('BIND_MODULE','Home');      
} 
// 引入ThinkPHP入口文件
require dirname(__FILE__).'/ThinkPHP/ThinkPHP.php';

到此,關(guān)于“Thinkphp通過一個入口文件怎么區(qū)分移動端和PC端”的學(xué)習(xí)就結(jié)束了,希望能夠解決大家的疑惑。理論與實踐的搭配能更好的幫助大家學(xué)習(xí),快去試試吧!若想繼續(xù)學(xué)習(xí)更多相關(guān)知識,請繼續(xù)關(guān)注億速云網(wǎng)站,小編會繼續(xù)努力為大家?guī)砀鄬嵱玫奈恼拢?/p>

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI