久久国产成人av_抖音国产毛片_a片网站免费观看_A片无码播放手机在线观看,色五月在线观看,亚洲精品m在线观看,女人自慰的免费网址,悠悠在线观看精品视频,一级日本片免费的,亚洲精品久,国产精品成人久久久久久久

分享

thinkphp如何來判斷訪客為手機端或是PC端

 一劍浮生似夢來 2016-10-28
文章詳細內(nèi)容

thinkphp如何來判斷訪客為手機端或是PC端

發(fā)布日期:2014年06月12日   來源:PHP1.CN     點擊:138528
摘要:近日準備給自己的網(wǎng)站做一個小升級,讓用戶在手機二維碼掃描的時候顯示適合手機端來展示的模版【我用的是ThinkPHP3.0】,代碼是參考別人的,我先說下大概的一個思路簡單兩步:統(tǒng)版本號....
轉載請注明來源:thinkphp如何來判斷訪客為手機端或是PC端

近日準備給自己的網(wǎng)站做一個小升級,讓用戶在手機二維碼掃描的時候顯示適合手機端來展示的模版【我用的是ThinkPHP3.0】,代碼是參考別人的

我先說下大概的一個思路 簡單兩步:

統(tǒng)版本號和瀏覽器以及它的版本號(貼出的代碼中數(shù)組中只有移動端信息,因此后面只需判斷是否為數(shù)組中的某一個值即可).

根據(jù)數(shù)組中的值來判斷訪客是否為手機,、pad,、之類的移動端,如果是的話就規(guī)定項目路徑,、名稱為你的手機端模版如 define('APP_NAME','mobi');

define('APP_PATH','./mobi/');

下面代碼的話我盡量加上注釋:

  1. //判斷是否屬手機 
  2. //代碼看上去很多,,其實就是數(shù)組里面顯得多而亂,不要被表面現(xiàn)象所嚇倒哦,! 
  3.  function is_mobile(){ 
  4.     $user_agent = $_SERVER['HTTP_USER_AGENT']; 
  5.  
  6.     $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"); 
  7.     $is_mobile = false; 
  8.     foreach ($mobile_agents as $device) {//這里把值遍歷一遍,,用于查找是否有上述字符串出現(xiàn)過 
  9.        if (stristr($user_agent$device)) { //stristr 查找訪客端信息是否在上述數(shù)組中,不存在即為PC端,。 
  10.             $is_mobile = true; 
  11.             break
  12.         } 
  13.     } 
  14.     return $is_mobile
  15. define('THINK_PATH','./CORE/'); 
  16. if(is_mobile()){ //跳轉至wap分組 
  17.  echo '您是手機端訪問的,,已跳轉到手機端'
  18.      define('APP_NAME','mobi'); 
  19.     define('APP_PATH','./mobi/'); 
  20. }else
  21.  echo '你是PC端訪問的'
  22.      define('APP_NAME','Home'); 
  23.     define('APP_PATH','./Home/');          
  24.  define('APP_DEBUG', false); 
  25. require THINK_PATH.'core.php'
轉載請注明來源:thinkphp如何來判斷訪客為手機端或是PC端
http://www./Content/thinkphp_RuHeLaiPanDuanFangKeWeiShouJiDuanHuoShi_PC_Duan.html
關注 第一PHP社區(qū) 微信公眾號,獲取更多最新PHP技術分享

  • 打醬油

  • 震驚

  • 呵呵


  • 鄙視

    本站是提供個人知識管理的網(wǎng)絡存儲空間,,所有內(nèi)容均由用戶發(fā)布,,不代表本站觀點。請注意甄別內(nèi)容中的聯(lián)系方式,、誘導購買等信息,,謹防詐騙,。如發(fā)現(xiàn)有害或侵權內(nèi)容,請點擊一鍵舉報,。
    轉藏 分享 獻花(0

    0條評論

    發(fā)表

    請遵守用戶 評論公約

    類似文章 更多