There is such a PHP which leads to an error. Cyclic redirection was detected on this page . How can I fix this error?

if(isset($_GET['aid']) && !is_numeric($_GET['aid'])) die('Hacking Attemp'); include ("GameEngine/Village.php"); include ("GameEngine/Chat.php"); $start = $generator->pageLoadTimeStart(); $alliance->procAlliance($_GET); if(isset($_GET['newdid'])) { $_SESSION['wid'] = $_GET['newdid']; if(isset($_GET['s'])){ header("Location: ".$_SERVER['PHP_SELF']."?s=".preg_replace("/[^a-zA-Z0-9_-]/","",$_GET['s'])); } else if(isset($_GET['aid'])){ header("Location: ".$_SERVER['PHP_SELF']."?aid=".preg_replace("/[^a-zA-Z0-9_-]/","",$_GET['aid'])); } else{ header("Location: ".$_SERVER['PHP_SELF']); } } if(isset($_GET['s'])){ $automation->isWinner(); } if(isset($_GET['fid'])){ $fid = preg_replace("/[^0-9]/","",$_GET['fid']); $query = "SELECT * FROM " . TB_PREFIX . "forum_cat WHERE id = ".$fid.""; //ппц $forum = mysqli_query($database->connection, $query); //? $forum_type = mysqli_fetch_array($forum); if($forum_type['forum_name'] != "" && $forum_type['forum_area'] == 0){ if($forum_type['alliance'] != $session->alliance){ header("Location: ".$_SERVER['PHP_SELF']); } } } else if(isset($_GET['fid2'])){ $fid = preg_replace("/[^0-9]/","",$_GET['fid2']); $q = "SELECT * FROM " . TB_PREFIX . "forum_cat WHERE id = ".$fid.""; //ппц $forum = mysqli_query($database->connection, $q); //? $forum_type = mysqli_fetch_array($forum); if($forum_type['forum_name'] != "" && $forum_type['forum_area'] != 1){ if($forum_type['forum_area'] == 0){ if($forum_type['alliance'] != $session->alliance){ header("Location: ".$_SERVER['PHP_SELF']); } } else if($forum_type['forum_area'] == 2){ if($forum_type['alliance'] != $session->alliance){ } else if($forum_type['forum_area'] == 3){ } } else { header("Location: ".$_SERVER['PHP_SELF']); } } } 

    1 answer 1

     if(isset($_GET['s'])){ header("Location: ".$_SERVER['PHP_SELF']."?s=".preg_replace("/[^a-zA-Z0-9_-]/","",$_GET['s'])); }else if(isset($_GET['aid'])){ header("Location: ".$_SERVER['PHP_SELF']."?aid=".preg_replace("/[^a-zA-Z0-9_-]/","",$_GET['aid'])); 

    Literally, this means:

    • If there is a GET 's' parameter, redirect to the same page with a slightly overfiltered GET 's' parameter.
    • If there is a GET 'aid' parameter, redirect to the same page with the GET 'aid' parameter slightly overfiltered.

    as soon as the s or aid parameter appears, the script begins to send the user to himself again with the s parameter or aid, to redirect again, to again detect the s parameter or aid ...