是什么导致重定向循环? [英] What Causes A Redirect Loop?

查看:154
本文介绍了是什么导致重定向循环?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的页面:

重定向页面: 如果用户具有打开的会话,请重定向到适当的资源 否则重定向到登录页面

Redirect Page: if user has an open session, redirect to the proper resource else redirect to login page

登录页面: 如果用户登录信息有效,则重定向到$ _SERVER ['HTTP_REFERER'] 否则显示登录页面

Login Page: if user login info is valid, redirect to $_SERVER['HTTP_REFERER'] else display login page

当您访问重定向页面时,它会发现您没有有效的会话,并重定向到登录页面.然后,您可以登录没有问题,但是在身份验证后,我收到此网页具有重定向循环". Chrome中的页面.

When you visit the redirect page, it sees that you do not have a valid session and redirects to the login page. You can then login no problems, but after authentication I receive the "This webpage has a redirect loop." page in Chrome.

这不是一个真正的循环,因为有几种解决方法(IE提供有效的登录详细信息并转到目标资源,提供无效的登录并接收错误消息等).但是我可以看到浏览器的混乱(从a到b再到a).

It's not a true loop, since there are several ways out (IE provide valid login details and go to destination resource, provide invalid login and receive error message, etc). But I can see the browser's confusion (going from a to b to a again).

有什么想法可以解决这个问题吗?

Any ideas how I can solve this problem?

欢呼

推荐答案

$ _ SERVER ['HTTP_REFERER']将始终是登录页面,因为必须在成功登录之前立即加载登录页面.因此,一旦成功登录,推荐人就是登录页面,因此登录页面会将您重定向到仍然成功登录的登录页面,从而使您一次又一次地登录.

$_SERVER['HTTP_REFERER'] will always be the login page since you have to load the login page right before you successfully login. So once you successfully login, the referrer is the login page, so the login page redirects you to the login page, which you still successfully logged in, so it logs you in over and over.

您可能不应该依赖$ _SERVER ['HTTP_REFERER']而是将它们尝试访问的页面存储在$ _SESSION或$ _COOKIE变量中.根据您的设置,最有可能的会话会更好.

Rather than relying on $_SERVER['HTTP_REFERER'] you should probably store the page they are trying to get to in either a $_SESSION or $_COOKIE variable. Most likely session will be better, depending upon your setup.

这篇关于是什么导致重定向循环?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆