Debugging a Browser Redirect Loop
cakephp, debugging, php
Solution
For debugging purposes, try inserting this first thing in your `AppController::beforeFilter()`:
$this->log("Here: {$this->here}, coming from: " . $this->referer(), LOG_DEBUG);
This will write to the log in `/app/tmp/logs/debug.log`. You could also combine this with overriding the redirect method in the `AppController`:
function redirect($url, $status = null, $exit = true) {
$trace = debug_backtrace();
$this->log("Redirecting to: " . Router::url($url) . ", initiated in {$trace[1]['file']} on line {$trace[1]['line']}", LOG_DEBUG);
parent::redirect($url, $status, $exit);
}
Problem
I am using CakePHP with the Auth and ACL components. My page loads fine for non-registered users, but if I try to log in as a registered user I get an infinite redirect loop in the browser. I am sure that this is some sort of permissions problem, but the problem exists even for users who have permissions for everything. The only way to prevent this behavior is to allow '*' in my AppController's beforeFilter method. What is the best way to debug this sort of problem? Thanks!