简体   繁体   English

登录/注册“重定向过多”错误

[英]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: index.php文件:

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

signup.php: 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. 我被重定向到signup.php页面,但是此后得到了too many redirects错误。 In server logs, there are just 302 redirects to signup.php page. 在服务器日志中,只有302重定向到signup.php页面。 I'm not redirecting anywhere else in signup.php . 我没有重定向signup.php其他任何地方。

Where could this error come from? 该错误从何而来?

Your header('Location: /signup'); 您的header('Location: /signup'); is failing because the file is actually called signup.php and /signup is a folder. 失败,因为该文件实际上称为signup.php/signup是一个文件夹。

and is interpreted as: /go_to_root/signup/index.php 并解释为: /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. 由于该文件夹不存在,因此它从最有可能的404循环到索引文件。

Therefore, you need to make it read as 因此,您需要将其读为

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

and add exit; 并添加exit; after each header, otherwise, your code will continue to execute. 在每个标头之后,否则,您的代码将继续执行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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