2014-04-16 3 views
0

좋아요, 다른 날에 여기에 게시했습니다. 도움이 많이되어 다시 방문하기로 결정했습니다. 같은 코드에 또 다른 문제가 있습니다. 내가 사용했던 소스를 "$ location_url2"라고 추가하고 싶었지만 코드에 맞는 두 번째 "$ content"를 추가했습니다. 두 소스의 차이점은 "$ location_url"은 아무 것도 없으면 빈 페이지를 반환하지만 아무것도 발견되지 않으면 "$ lcation_url2"가 index.php로 리디렉션되지만 URL에 확장명을 유지합니다 ... 코드 사용 :페이지를 정확히 찾을 수 없을 때 리디렉션

<?php 
    if(isset($_POST['search'])) { 
     $search_text = $_POST['search']; 
     $location_url = "http://cydia.saurik.com/package/{$search_text}/"; 
     $location_url2 = "http://rpetri.ch/cydia/{$search_text}/"; 
     $content = @file_get_contents($location_url); 
     $content2 = @file_get_contents($location_url2); 

     if($content) { 
      header("Location: {$location_url}"); 
     } else if($content2) { 
      header("Location: {$location_url2}"); 
     } else { 
      header("Location: suggest.php"); 
     } 
    } 
?> 

HTML 코드 것은 : 당신이 아무 것도 발견되지 때 두 개의 링크가 아무것도 돌려주지 않는 절대적으로 확신하지 않는 한

<div id="content"> 
    <div id="search"> 
    <form method="POST" name="search" action="search.php"> 
     <input type="text" name="search" name="placeholder" placeholder="Search Tweaks..."/> 
     <input type="submit" name="submit" value="Search"/> 
    </form> 
    </div> 
</div> 

답변

0

이 수행하기 어려운 수 있습니다. 두 위치 중 하나가 404와 같은 값을 반환하면 스크립트는 404를 실제 콘텐츠로 해석하고 거기로 리디렉션합니다. 사이트에 "콘텐츠가 있는지 여부"를 확인하는 대체 방법을 찾아야 할 수도 있습니다.

이 같은 200 헤더를 확인할 수 있습니다 :

$header=get_headers($url,true); 

하고 다음 테스트 $ 헤더 [0] 거기에 "200"을 가지고 ... 그것은 비록 사기 코드가 있습니다. 언제든지 URL 중 하나에서 HTTP/1.1 200 OK를 사용하여 예기치 않은 결과가 반환되는 경우 스크립트에서 문제가 없다고 판단됩니다.

코드에 중복성이 많이 있습니다. 지금 $ location_url2에 $ location_url에 내용이있는 경우에도 $ location_url2가 다운로드되는데, 이는 리소스를 굽는 데 필요한 것보다 느리게 만듭니다 ...

나는이 라인을 따라 갈 것입니다 : 매우 높은 URL의 반환에 따라) :

<? 

$search_text=filter_input(INPUT_POST,"search",FILTER_SANITIZE_ENCODED); 

if($search_text!=""){ 
    $location_url = "http://cydia.saurik.com/package/{$search_text}/"; 
    $location_url2 = "http://rpetri.ch/cydia/{$search_text}/"; 

    [email protected]_header($location_url,true); 
    if(strpos($content,"200 OK")!==false) 
     header("Location: {$location_url}"); 
    else{ 
     [email protected]_header($location_url2,true); 
     if(strpos($content,"200 OK")!==false) 
      header("Location: {$location_url2}"); 
     else 
      header("Location: http://www.amazingjokes.com"); 
    } 
} 
관련 문제