Restoration
1/30/2017 - 12:21 PM

PHPでユーザーエージェントを判別

PHPでユーザーエージェントを判別

<?php
// モバイルで接続すると別のURLへ遷移させる
// 環境変数よりユーザーエージェントを取得し判別
$user_agent = $_SERVER['HTTP_USER_AGENT'];
if((strpos($user_agent,'iPhone')==true)||(strpos($user_agent,'iPod')==true)||(strpos($user_agent,'Android')==true)) {
     header('Location:URL');
     exit();
}
?>