2007/08/07 内容の改変、実際のコードを追加。
という話。
例えば、PC用のURL(e.g. http://www.example.jp)とモバイル用のURL(e.g. http://m.example.jp)を別々に設定しているサイトがあるけど、そういうものは人間が判断せずに、サーバ側でUserAgentとIPアドレスからPCかモバイルかを判別して専用のページに飛ばすかした方がスマートではないかと。
それに技術的にもそれほど難しい事でもないはずです。たとえばPHP5でPEARのNet_UserAgent_Mobileパッケージを使うならば、以下のように書けるはずです。
require_once('Net/UserAgent/Mobile.php');
$agent = &Net_UserAgent_Mobile::singleton();
if ($agent->isDoCoMo()){
header("Location: http://mobile.example.jp/");
} elseif ($agent->isVodafone()){
header("Location: http://mobile.example.jp/");
} elseif ($agent->isEZweb()):{
header("Location: http://mobile.example.jp/");
} else{
// PC用の処理
}携帯は全部同じURIに飛ばしてますが、将来的に携帯会社別に判別することも考えてちょっと冗長気味に書いてます。
参考リンク
PEAR::Net_UserAgent_Mobile 3G対応携帯判別(ケータイ判別) – PHP::PEAR – dozo PukiWiki
Popularity: 2% [?]
- キーワード:



読者のコメント
0件