简体   繁体   中英

why does this page redirect in a loop? (simple session login page)

Ok ive asked this question on here today but this code is much easier to follow. i still dont understand why this page would redirect in a loop?

<?php
ini_set('display_errors', 1);

session_start();
$_SESSION['passw'] = "word";
$_POST['passw'] = "word";

if($_POST['passw'] === "word" ){
echo 'post ok';
$_SESSION['passw'] = "word";
unset($_POST);
session_write_close();
header('Location: '.$_SERVER['PHP_SELF']);
}
if($_SESSION['passw'] === "word") {

echo 'password checked ok<br>';

}

?>

Well, let's show just the relevant lines:

$_POST['passw'] = "word";
if($_POST['passw'] === "word" ){
    header('Location: '.$_SERVER['PHP_SELF']);
}

Basically you are saying

 if (true) {
     reloadThePage();
 }

Because you are setting the value to "word" immediately before your IF statement.

$_POST['passw'] = "word";

if($_POST['passw'] === "word" ){

So, to fix, remove this:

$_POST['passw'] = "word";

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM