简体   繁体   中英

login/signup 'too many redirects' error

I'm getting this annoying error which I can't seem to get rid of.

Relevant snippets:

index.php:

if(isset($_SESSION['isLoggedIn']) && $_SESSION['isLoggedIn']===true){
    $isLoggedIn = true;
}else{
    $_SESSION['isLoggedIn'] = false;
    header('Location: /signup');
}

signup.php:

if(isset($_SESSION['isLoggedIn']) && $_SESSION['isLoggedIn']===true){
    header('Location: /');
} else {
    $_SESSION['isLoggedIn'] = false;
}

I get redirected to signup.php page, but after that get too many redirects error. In server logs, there are just 302 redirects to signup.php page. I'm not redirecting anywhere else in signup.php .

Where could this error come from?

Your header('Location: /signup'); is failing because the file is actually called signup.php and /signup is a folder.

and is interpreted as: /go_to_root/signup/index.php

Since that folder doesn't exist, it's looping over from a most likely 404 and to an index file.

Therefore, you need to make it read as

header('Location: /signup.php');

and add exit; after each header, otherwise, your code will continue to execute.

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