tekina tekina - 1 year ago 60
PHP Question

PHP login/signup 'too many redirects' error (snippet attached)

I've just started with PHP, and 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 signup.php 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 signup.php.

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