Diagnosing the cause of a redirect loop in a CodeIgniter app

Terry Woods
Terry Woods used Ask the Experts™
on
I seem to have a redirect loop in my app, and I'm trying to track down the cause.

My controller home.php is the default controller for my app, and contains:
	function index()
	{
		if (!$this->tank_auth->is_logged_in()) {
			dbglog('redirecting');
			redirect('/auth/login/');
		} else {

Open in new window


The dbglog() call is just debugging to a log file. When I add debugging to the auth controller login function, it doesn't get output.

The word "redirecting" is written to my log file 21 times before an error is displayed by Chrome. Firefox doesn't seem to detect the problem (the page doesn't load; it just keeps trying).

Is there some kind of logging I can turn on in CodeIgniter to figure out what's happening?

It's possible the issue is with Apache, in which case I'll need to try to find out what logging is done by that, and where it gets written to. I'm using a (shared) corporate Linux server.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Is there some kind of logging I can turn on in CodeIgniter to figure out what's happening?


ref. http://ellislab.com/codeigniter/user-guide/general/errors.html
Terry WoodsIT Guru
Most Valuable Expert 2011

Author

Commented:
Thanks for the link. I suspect that logging needs to be manually added though, so it requires me to understand the problem that I don't fully understand. I will have a play with the log threshold settings though and see what happens.
Most Valuable Expert 2018
Distinguished Expert 2018
Commented:
In the config.php file in the application/config folder, turn logging up to maximum - 4

$config['log_threshold'] = 4;

Don't leave this in place for too long because your log files (usually in application/logs) will get huge.

Also double check what's going on in your auth/login method - that may be causing the loop
I have solved this issue by setting the value of "$config['sess_encrypt_cookie']" to "TRUE"
In my case it’s due to sanitizing of cookie values by security class.
But Encryption of cookie data solves the problem.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial