日韩中文精品无码_91尤物在线看网址_欧美成 人影片 aⅴ免费观看_久草免费福利资源站在线观看

內(nèi)頁(yè)Banner背景圖
創(chuàng)絡(luò)講堂
白色波浪圖形
灰色波浪圖形 灰色波浪圖形
白色波浪圖形 白色波浪圖形
白色波浪圖形 白色波浪圖形
白色波浪圖形 白色波浪圖形
本文于2014-12-04最后更新,距今已超過(guò)1年,如不符合現(xiàn)在的實(shí)際情況,可聯(lián)系創(chuàng)絡(luò)客服獲取幫助或查閱近期文章。

手機(jī)版網(wǎng)站和電腦版網(wǎng)站的自動(dòng)識(shí)別并跳轉(zhuǎn)

大家可以嘗試一下用手機(jī)訪問(wèn)我公司官方網(wǎng)站(www.xatjqxtz.com),系統(tǒng)會(huì)自動(dòng)識(shí)別并跳轉(zhuǎn)到手機(jī)版網(wǎng)站去;同樣的,如果使用電腦訪問(wèn)手機(jī)版網(wǎng)站(m.chuangluo.com),系統(tǒng)也會(huì)自動(dòng)識(shí)別并跳轉(zhuǎn)到對(duì)應(yīng)的電腦版網(wǎng)址去。目前已經(jīng)有很多同時(shí)擁有手機(jī)版網(wǎng)站和電腦版網(wǎng)站的大型企業(yè)網(wǎng)站使用了這樣的技術(shù),那小型公司網(wǎng)站如果也有這種需求的話,應(yīng)該如何實(shí)現(xiàn)呢?

實(shí)現(xiàn)手機(jī)版網(wǎng)站和電腦版網(wǎng)站的自動(dòng)識(shí)別并跳轉(zhuǎn)的條件

首先肯定是需要有兩個(gè)不同版本的網(wǎng)站,這是必然的!第二個(gè)條件是這兩個(gè)版本的網(wǎng)站數(shù)據(jù)要基本同步。以我公司官方網(wǎng)站為例,電腦版網(wǎng)站的頁(yè)面比手機(jī)版的多,手機(jī)版有的頁(yè)面,電腦版全部都有。這是因?yàn)槲覀冸娔X版網(wǎng)站上有很多靜態(tài)的專題頁(yè),而手機(jī)版則沒(méi)有,例如:網(wǎng)站價(jià)格評(píng)估、域名查詢等。因此,我們只需要實(shí)現(xiàn)自動(dòng)識(shí)別這一部分頁(yè)面并跳轉(zhuǎn)即可。

如何實(shí)現(xiàn)自動(dòng)識(shí)別并跳轉(zhuǎn)

由于我公司目前開發(fā)網(wǎng)站的語(yǔ)言是主流的PHP,因此我們此處只討論P(yáng)HP的實(shí)現(xiàn)方法,其他語(yǔ)言請(qǐng)直接參考本方法稍作修改即可。核心原理是通過(guò)程序判斷$_SERVER[?HTTP_USER_AGENT?]中是否包含了手機(jī)訪問(wèn)的一些特征信息,例如屏幕尺寸,手機(jī)品牌或者其他特征信息。此處一提供兩個(gè)方法供大家參考:

方法一:

判斷函數(shù)

function is_mob() {
    $user_agent = $_SERVER[?HTTP_USER_AGENT?];
    $mob_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_mob = false;
    foreach ($mob_agents as $device) {
     if (stristr($user_agent, $device)) {
   $is_mob = true;
   break;
     }
    }
    return $is_mob;
   }

調(diào)用函數(shù)

if(is_mob())
   {
  //通過(guò)$_SERVER["REQUEST_URI"]取出具體頁(yè)面網(wǎng)址,修改域名后并跳轉(zhuǎn)。
  }

方法二:

$ua = strtolower($_SERVER[?HTTP_USER_AGENT?]);
$uachar = "/(nokia|sony|ericsson|mot|samsung|sgh|lg|philips|panasonic|alcatel|lenovo|cldc|midp|mobile)/i"
if(($ua == ?? || preg_match($uachar, $ua))&& !strpos(strtolower($_SERVER[?REQUEST_URI?]),?wap?))
{
 //通過(guò)$_SERVER["REQUEST_URI"]取出具體頁(yè)面網(wǎng)址,修改域名后并跳轉(zhuǎn)。
}

兩種方法中推薦使用第一種,識(shí)別率相對(duì)較高;第二種效率更高,但識(shí)別率相對(duì)較低。兩種方法均整理自互聯(lián)網(wǎng),大家在使用的時(shí)候可以稍加修改,以實(shí)現(xiàn)更多功能。

上一條 返回目錄 下一條
更多閱讀選擇
相關(guān)文章
我們推薦了一些您可能也會(huì)感興趣的文章
客服電話
  • 0755-23698839
  • 134-1757-3710
  • 132-6576-8769
創(chuàng)絡(luò)建站客服二維碼
不出售過(guò)期域名
微信咨詢