2016-06-17 3 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

관련 문제