如何确定标头重定向来自何处
我需要找到一种方法,使 header() 重定向的目标可以确定哪个页面发起了重定向。我们正在使用 mod_auth_cas hack 来验证登录。由于我们不能将整个站点放在 mod_auth_cas 后面,因此我们在 .htaccess 中有一个包含 AuthType Cas 的子目录。对于登录,我们提供一个指向 /cas 目录的链接,处理 cas,将返回的用户 ID 添加到 $_SESSION 并与我们的权限数据库进行比较,然后页面标题重定向到主页。
这种舞蹈在刚返回主页时效果很好,但我们希望当 $_SESSION 中没有 userid 时需要登录的页面重定向到 cas。当用户登录并且我们取回用户 ID 时,它会重定向回发送该用户 ID 的页面,而不是主页。这种回顾标头重定向的原始页面的能力在网站的其他部分会很方便。
/cas/index.php 如何确定哪个页面发起了重定向?当用户打开多个页面时,如何避免冲突,同时被重定向到其中一个页面的 cas,转到第二个页面,他们也被重定向到 cas,完成 cas 返回到第一个页面,完成它再次重定向到第二页而不是第一页?而且这个解决方案必须是纯 PHP,没有 javascript 跟踪。
I need to find a way that the target of a header() redirect can determine what page initiated the redirect. We are using a mod_auth_cas hack to validate logins. Since we cannot have the entire site behind mod_auth_cas we have a sub-directory with AuthType Cas in the .htaccess. for logins we give a link to the /cas directory, the cas is processed, the returned userid is added to the $_SESSION and compared to our permissions database, then the page is header redirected to the homepage.
This dance works well when just returning to the homepage but we would like pages that require a login to redirect to the cas when there is no userid in $_SESSION. And when the user logs in and we get the userid back it redirects back to the page that sent it there, not the homepage. And this ability to look back at the originating page of a header redirect would be handy in other parts of the site.
How can the /cas/index.php determine what page originated the redirect? How do I avoid a collision where a user has multiple pages open, is simultaneously is redirected to the cas on one, goes to a second page where they are also redirected to the cas, compeletes the cas goes back to the first one, completes it again and is redirected to the second page not the first one? And this solution has to be pure PHP, no javascript tracking.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
有几种方法可以做到这一点。
- 在重定向之前将原始 URL 存储在会话中
- 在登录页面上,从 $_SERVER 变量中获取引用 URL,并在登录后重定向到该 URL
- 调整重定向,以便将当前 URL 添加到 get/post 变量中登录页面
-- noaccess.php 重定向到 login.php?ret_url=noaccess.php (您可能希望使用完整的 url 并对它进行 url 编码)
THere are a few ways you can do this.
-Either store the original URL in the session before the redirect
-On the login page, grab the referring url from the $_SERVER variable and redirect to that after login
-Adjust your redirect so it adds the current URL to the get/post variables on the login page
-- noaccess.php gets redirect to login.php?ret_url=noaccess.php (you would probably want to use the full url and url encode it)
无需修改或添加任何代码,您就可以安装 XDebug php 扩展并打开分析。它将吐出一个包含有关调用堆栈信息的cachegrind 文件。您可以在 kcachegrind 之类的工具中打开它,以直观地了解调用 header() 的时间。
Without modifying or adding any code at all you can install the XDebug php extension and turn on profiling. It will spit out a cachegrind file containing info about the callstack. You can open it in something like kcachegrind to get a visual representation of when the call to header() happened.