[php] 今更モバイルの振り分けの方法

このエントリーを含むはてなブックマークはてなブックマーク - [php] 今更モバイルの振り分けの方法 Share on Tumblr Googleブックマークに追加 Bookmark this on Delicious このエントリをつぶやく

まぁメモなのですが、PHPでモバイル端末の振り分けをするいい方法を見たので、
書いておきます。

strpos使うと結構早いらしい。

define('CARRIER_DOCOMO',   1);
define('CARRIER_KDDI',     2);
define('CARRIER_SOFTBANK', 3);
define('CARRIER_EMOBILE',  4);
define('CARRIER_IPHONE',   5);
define('CARRIER_PHS',      6);
$user_agent = $_SERVER['HTTP_USER_AGENT'];

//DoCoMo
if ( strpos($user_agent, 'DoCoMo') !== false ) {
    $carrier = CARRIER_DOCOMO;
}
//Softbank
elseif ( strpos($user_agent, 'SoftBank') !== false ) {
    $carrier = CARRIER_SOFTBANK;
}
elseif ( strpos($user_agent, 'Vodafone') !== false ) {
    $carrier = CARRIER_SOFTBANK;
}
elseif ( strpos($user_agent, 'J-PHONE') !== false ) {
    $carrier = CARRIER_SOFTBANK;
}
elseif ( strpos($user_agent, 'MOT-C980') !== false ) {
    $carrier = CARRIER_SOFTBANK;
}
elseif ( strpos($user_agent, 'MOT-V980') !== false ) {
    $carrier = CARRIER_SOFTBANK;
}
//KDDI
elseif ( strpos($user_agent, 'KDDI-') !== false ) {
    $carrier = CARRIER_KDDI;
}
//EMOBILE
elseif ( strpos($user_agent, 'emobile') !== false ) {
    $carrier = CARRIER_EMOBILE;
//iPhone
}
elseif ( strpos($user_agent, 'iPhone') !== false ) {
    $carrier = CARRIER_IPHONE;
}
//PHS
elseif ( strpos($user_agent, 'WILLCOM') !== false ){
    $carrier = CARRIER_PHS;
}
elseif ( strpos($user_agent, 'DDIPOCKET') !== false ){
    $carrier = CARRIER_PHS;
}
Posted 火曜日, 2月 9th, 2010 under php.
blog comments powered by Disqus