tekina tekina - 1 year ago 67
PHP Question

login/signup 'too many redirects' error

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

Relevant snippets:


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


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

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

Where could this error come from?

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download