Welcome Guest, Not a member yet? Register   Sign In
Redirect causes infinite loop
#1

[eluser]tokyotech[/eluser]
I'm using CodeIgniter's redirect function to go back to the same method that called it. This is to ensure that the cookies that were unset in user->logOut start taking effect (that's the nature of cookies). However, the redirect should not go on infinitely because of my control logic. Why, then, is Firefox reporting that there is an infinite loop and takes me to an error page?

Code:
public function logout($firstTime = true)
{
    $this->user->logOut();
  
    $this->load->view('account/loggedOut');
    
    if ($firstTime) {
        redirect('account/logout/false');
    }
}
#2

[eluser]tokyotech[/eluser]
OK. Basic CS101.

Code:
'false' !== false

My bad.
#3

[eluser]Phil Sturgeon[/eluser]
I tend to use 0 and 1 over true and false as they come through the URL ok.

Code:
0 == false
1 == true

0 !== false
1 !== true
#4

[eluser]kurucu[/eluser]
Agreed. Also, the condition is at risk as the first time generally means $firstime is unset (i.e. the false condition) and thus if false was dropped it would turn true again in the function declaration.

Perhaps swapping the logic around would help, so that the conditions false, unset, zero and default are all the same, and the confirmation condition becomes true...

Code:
public function logout($confirmed = FALSE)
{
    $this->user->logOut();
  
    $this->load->view('account/loggedOut');
    
    if ($confirmed == FALSE) {
        redirect('account/logout/1'); // or indeed any value at all, I think.
    }
}

I use == rather than === here to trap zeros, unsets, the word False and so on.




Theme © iAndrew 2016 - Forum software by © MyBB