2010-08-12 64 views
0

我必須製作2個我的網站,即1個移動電話版本和1個PC版本。所以我有一個腳本如下: -檢測移動設備的腳本是什麼

<?php 
if (stristr($ua, "Windows CE") or stristr($ua, "AvantGo") or 
    stristr($ua,"Mazingo") or stristr($ua, "Mobile") or stristr($ua, "T68") or 
    stristr($ua,"Syncalot") or stristr($ua, "Blazer") or 
    stristr($ua,"Mozilla") or stristr($ua,"Firefox")) 
{ 
    $DEVICE_TYPE="MOBILE"; 
} 
if (isset($DEVICE_TYPE) and $DEVICE_TYPE=="MOBILE") 
{ 
    $location='mobile/entry.html'; 
    header ('Location: '.$location); 
    exit; 
} 
else 
{ 
    $location='entry.html'; 
    header ('Location: '.$location); 
    exit; 
} 
?> 

該腳本可以與電腦效果很好,但如果我試圖從手機訪問我的網站,我想我不能重定向到同一頁面。

任何人都可以幫我解決這個問題嗎?

在此先感謝。

+0

可能重複【如何檢測手機瀏覽器功能(http://stackoverflow.com/questions/3428234/how-to-detect-mobile-browser -capability) – 2010-08-12 10:40:07

+0

@Pekka大多數鏈接在Sarfraz發佈不幸工作 – Sotiris 2010-08-12 10:55:09

回答

0

最好的辦法是不要嘗試和重定向基於用戶代理嗅探,而是把你的移動內容到具體的網址,並讓那些可供選擇。用戶代理嗅探在某點上是可以的,但是你不能100%依賴它。與此相關,PPK's post on javascript detection是很好的閱讀。這就是說,如果你在做用戶代理重定向時遇到了麻煩,那麼你將需要一些方法來更新你的設備列表和用戶代理字符串 - 類似codeigniter的user agent class將會更加有用從長遠來看。