페이지가 존재하지 않거나 포함되어서는 안되는 내용이 있는지 확인해야하는이 코드가 있습니다. 어떤 이유로 든 페이지가 아닌 다른 페이지로 이동하면 더 구체적으로 406 오류가 발생합니다. 홈 페이지 ($ _GET = "").
코드는 다음과 같습니다. 미리 도와 주셔서 감사합니다. :)
$currentpage = $_GET['a'];
$pages[1] = "";
$pages[2] = "help";
$pages[3] = "work";
$pages[4] = "download";
$pages[5] = "process";
$pages[6] = "safariex";
$pages[7] = "services";
if(isset($_GET) && !ctype_alpha($_GET) && $_GET['a'] != ""){
header("Location: http://pattersoncode.ca/error.php?ec=406");
}
if (!ctype_alpha($_GET['a']) && $_GET['a'] != "") {
header("Location: http://pattersoncode.ca/error.php?ec=406");
}
if ( ! in_array( $currentpage, $pages ) )
{
header("Location: http://pattersoncode.ca/error.php?ec=404");
}
나는 이것이 잘못되었다고 생각합니다.
!ctype_alpha($_GET)
$_GET
문자열이 아니라 배열입니다. ctype_alpha($_GET)
항상 거짓입니다.
대신 이것을 원할 것입니다.
if(!isset($_GET["a"]) || !ctype_alpha($_GET["a"])) {
header("Location: http://pattersoncode.ca/error.php?ec=406");
exit();
}
두 가지 조건을 모두 처리해야합니다.
대부분의 경우 리디렉션을 수행 할 때 exit ()를 수행하려고합니다.
가능하다면 리디렉션보다는 실제 http 응답 코드를 보내는 것이 좋습니다.
header('HTTP/1.1 406 Not Acceptable', true, 406);
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다