這篇文章將為大家詳細講解有關(guān)thinkphp如何判斷訪客為手機端或PC端,小編覺得挺實用的,因此分享給大家做個參考,希望大家閱讀完這篇文章后可以有所收獲。
創(chuàng)新互聯(lián)建站是一家朝氣蓬勃的網(wǎng)站建設(shè)公司。公司專注于為企業(yè)提供信息化建設(shè)解決方案。從事網(wǎng)站開發(fā),網(wǎng)站制作,網(wǎng)站設(shè)計,網(wǎng)站模板,微信公眾號開發(fā),軟件開發(fā),小程序制作,十載建站對純水機等多個方面,擁有豐富的網(wǎng)站設(shè)計經(jīng)驗。一、問題:
近日準備給自己的網(wǎng)站做一個小升級,讓用戶在手機二維碼掃描的時候顯示適合手機端來展示的模版【我用的是ThinkPHP3.0】,代碼是參考別人的
二、實現(xiàn)方法:
這里先說下大概的一個思路 簡單兩步:
統(tǒng)版本號和瀏覽器以及它的版本號(貼出的代碼中數(shù)組中只有移動端信息,因此后面只需判斷是否為數(shù)組中的某一個值即可).
根據(jù)數(shù)組中的值來判斷訪客是否為手機、pad、之類的移動端,如果是的話就規(guī)定項目路徑、名稱為你的手機端模版如
復制代碼 代碼如下:
define('APP_NAME','mobi');
define('APP_PATH','./mobi/');
下面代碼的話我盡量加上注釋:
//判斷是否屬手機 //代碼看上去很多,其實就是數(shù)組里面顯得多而亂,不要被表面現(xiàn)象所嚇倒哦! 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; } define('THINK_PATH','./CORE/'); if(is_mobile()){ //跳轉(zhuǎn)至wap分組 echo '您是手機端訪問的,已跳轉(zhuǎn)到手機端'; define('APP_NAME','mobi'); define('APP_PATH','./mobi/'); }else{ echo '你是PC端訪問的'; define('APP_NAME','Home'); define('APP_PATH','./Home/'); } define('APP_DEBUG', false); require THINK_PATH.'core.php';
關(guān)于“thinkphp如何判斷訪客為手機端或PC端”這篇文章就分享到這里了,希望以上內(nèi)容可以對大家有一定的幫助,使各位可以學到更多知識,如果覺得文章不錯,請把它分享出去讓更多的人看到。
網(wǎng)頁名稱:thinkphp如何判斷訪客為手機端或PC端-創(chuàng)新互聯(lián)
地址分享:http://vcdvsql.cn/article4/ejhie.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供云服務(wù)器、App設(shè)計、定制開發(fā)、網(wǎng)站建設(shè)、微信公眾號、網(wǎng)站導航
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容