在apache中跟踪无限循环重定向
我有一个 PHP 脚本导致无限重定向循环,但我不知道如何检测它。有什么方法可以检测到这个吗?我可以向 .htaccess 添加任何命令以将重定向写入日志吗?
提前致谢,
I have a PHP script causing a infinite redirection loop and i don't know how to detect it. is there any way to detect this? can i add any command to my .htaccess to write redirections into a log?
thanks in advance,
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在 PHP 中以简单的方式进行调试实际上是一项繁琐的工作。您需要的是在每行后面提供一些“echo”语句(输出虚拟文本),然后是“exit”命令语句。
然后重定向循环将不起作用,因为“退出”使程序计数器可停止,并且您现在可以按顺序调试出错的地方。
至于“.htaccess”命令,您将不需要任何这样的东西。请在您的根文件夹中检查“error.log”文件,您在其中托管了网站的index.php 文件。如果您在某些文本编辑器(如写字板)中打开此文件,您将看到所有错误列表,以及日期和时间。时间。
编辑(提供一个示例):-
假设您有一个如下所示的页面:-
现在更改代码以这种方式进行调试:-
如果有效,请再次更改为:-
现在如果有效,则意味着“header.php”文件中没有问题,否则您在包含的文件中会遇到一些问题;您需要在“header.php”文件中以相同的方式开始调试。
希望有帮助。
Debugging in PHP in simple way is actually a cumbersome effort. What you will need is you should provide some "echo" statement (outputting a dummy text) after each line, followed by the "exit" command statement.
Then the redirection loop will not work because "exit" is making the program counter stoppable, and o you can now debug sequentially where you are going wrong.
As regards to the ".htaccess" command, you will not need any such thing. Please check in your root folder for the "error.log" file, where you have hosted your website's index.php file. If you open this file in some text editor (like Wordpad), you will see all the list of errors, along with date & time.
EDIT (providing with one example):-
Let's say you have one page like the following:-
Now change the code to debug in this way:-
If it works, change again to:-
Now if it works, that means you have no problem in the "header.php" file, otherwise you are having some problem in that included file & you will need to start debugging in the same way in that "header.php" file.
Hope it helps.
的实例
更改to
(很可能是 foo = bar,但您可能有一个包含多个页面的循环...)
Change instances of
to
(Most likely foo = bar, but you could have a loop containing more than one page...)
我目前正在为无限重定向而苦苦挣扎。由于应用程序和下班后编程周期的复杂性,并非所有重定向都以正确的方式进行。
如果您在开始时设置了会话(假设是自动加载文件),您就不能简单地检查会话是否循环自身。
我的建议是,您将变量重定向写入外部文件(即使用 file_put_contents 或 fwrite),这样即使您的浏览器检测到一些误解,您也可以跟踪执行。写入外部文件使您有机会跟踪执行,即使您在屏幕上看不到任何回显。
无限重定向通常来自于编写代码时不必要的复杂性以及形成项目结构时的误解。
祝你好运!
I'm currently struggling with infinite redirection myself. Due to complexity of the aplication and afterhours programming cycle not all redirections have been made the right way.
If you've set session at the beginning (let say autloader file) you cannot simply check if session loops itself.
My advice is that you write variables redirection to an external file (i.e. using file_put_contents or fwrite) so that you can follow execution even if your browser detects some misconception. Writing to an external file gives you an oportunity to follow execution even though you cannot see any echo on screen.
Infinite redirections usually come from unnecessary complication while writing code and misunderstanding in forming project structure.
Good luck!