1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | <?php $url="https://ktai"; $smaho="https://smaho"; $ua=$_SERVER['HTTP_USER_AGENT']; if((strpos($ua,'DoCoMo')!==false)||(strpos($ua,'KDDI')!==false)||(strpos($ua,'UP\.Browser')!==false)||(strpos($ua,'J-PHONE')!==false)||(strpos($ua,'Vodafone')!==false)||(strpos($ua,'SoftBank')!==false)) { header("Location: $url"); } elseif((strpos($ua,'iPhone')!==false)||(strpos($ua,'Android','Mobile')!==false)) { header("Location: $smaho"); exit(); } ?> |
[reference]
=====================================================
=====================================================
$ua = $_SERVER['HTTP_USER_AGENT'];
if(mb_strpos($ua,'iphone') || mb_strpos($ua,'ipod')) {
iphone またはipodの場合の処理
} else {
それ以外のブラウザの場合の処理
}
?>
[EX]
$ua = $_SERVER['HTTP_USER_AGENT'];
if(mb_strpos($ua,'iphone') || mb_strpos($ua,'ipod')) {
return $pc = 0;
} else {
return $ pc = 1;
}
?>
[変数$pcの値を1で返す]
PC用の記述
iphone用の記述