2016-06-17 27 views
0

index.phpページの最上部でこのスクリプトを使用しているプラ​​ットフォームを検出しようとしていますが、コンピュータのブラウザ(google.comにリダイレクトする必要があります)にアクセスするとリダイレクトされません。この単純なリダイレクトスクリプトはなぜ機能しませんか?

<?php 

//Detect special conditions devices 
$iPod = stripos($_SERVER['HTTP_USER_AGENT'],"iPod"); 
$iPhone = stripos($_SERVER['HTTP_USER_AGENT'],"iPhone"); 
$iPad = stripos($_SERVER['HTTP_USER_AGENT'],"iPad"); 
$Android = stripos($_SERVER['HTTP_USER_AGENT'],"Android"); 
$webOS = stripos($_SERVER['HTTP_USER_AGENT'],"webOS"); 

//do something with this information 
if($iPod || $iPhone){ 
header("Location: http://example.com/myOtherPage.php"); 
}else if($iPad){ 
//browser reported as an iPad -- do something here 
}else if($Android){ 
header("Location: http://example.com/myOtherPage.php"); 
}else if($webOS){ 
header("Location: http://google.com"); 
} 

?> 

おかげ

+0

'のvar_dump($ _、SERVER [ 'HTTP_USER_AGENT']を)リダイレクトされていないカテゴリのいずれかに落ちていないので;' - あなたは何を得るのですか? –

答えて

0

私はそのスクリプトがユーザーエージェントを引っ張っていないからだと賭けるだろう。その条件の最後にelseを追加します。それは

<?php 
     if($iPod || $iPhone){ 
      header("Location: http://example.com/myOtherPage.php"); 
     }else if($iPad){ 
      //browser reported as an iPad -- do something here 
     }else if($Android){ 
      header("Location: http://example.com/myOtherPage.php"); 
     }else if($webOS){ 
      header("Location: http://google.com"); 
     }else{ 
      echo 'User agent not detected'; 
     } 
+0

はい、エコーが検出されません。なぜ/私は何ができるのですか? – kk1zx

+0

Jon Statedのように、 'var_dump($ _ SERVER ['HTTP_USER_AGENT']); 'あなたのユーザエージェントが何であるかを見て、あなたの条件文にそれを加えてください。どのデバイス/ブラウザを使用していますか?また、ユーザーエージェントに基づいて何か重要なことを行っている場合は、これがなりすましになる可能性があることに注意してください。 – ksealey

関連する問題