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,
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,
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:-
<?php
session_start();
include_once("includes/header.php");
$var1 = 'blah blah';
// some code
$var2 = 'some more blah blah';
// some code again
// may be some more code
include_once("includes/footer.php");
?>
Now change the code to debug in this way:-
<?php
session_start();
echo 'test 1';
exit;
// other code of yours comes after this line
?>
If it works, change again to:-
<?php
session_start();
include_once("includes/header.php");
echo 'test 2';
exit;
// other code of yours comes after this line
?>
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.
Change instances of
header ("Location: foo.php");
to
//header ("Location: foo.php");
echo "redirecting to foo.php on line ## of bar.php";
exit;
(Most likely foo = bar, but you could have a loop containing more than one page...)