Weird issue with verifying variable in PHP -
i have code supposed check if page doesn't exist, or if contains shouldn't, , reason it's throwing error @ me, more 406, if go page other home page ($_get = "").
here's code , in advance :)
$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"); }
i believe wrong:
!ctype_alpha($_get)
$_get
array, not string. ctype_alpha($_get)
equal false.
you want instead:
if(!isset($_get["a"]) || !ctype_alpha($_get["a"])) { header("location: http://pattersoncode.ca/error.php?ec=406"); exit(); }
which should take care of both 406 conditions.
in cases want exit() when redirect.
if possible better send actual http response code rather redirect:
header('http/1.1 406 not acceptable', true, 406);
Comments
Post a Comment