0

When I click Logout, I'm unable to unset the value of the session variable. Please find my code below. I'm not sure where I'm going wrong

View:

<? if (!isset($this->session->userdata['user_full_name'])): ?>
<li class=""><a href="#" onclick="Login()">Login with FB</a></li>               
<? endif; ?>


<? if (isset($this->session->userdata['user_full_name'])): ?>
<li class=""><a href="#"><? echo $this->session->userdata['user_full_name']; ?></a></li>
<li class=""><a href="" onclick="Logout()">Logout</a></li>
<? endif; ?>

JS

function Logout()
{
FB.logout(function(response) {
    confirm("You have successfully logged out from FB");
    window.location.href = 'http://localhost:8080/auth/logout';
    //window.location.reload();
    console.log(response);      
});
}

Controller

function logout()
{
    $this->session->set_userdata(array(
                        'user_email'          => '',
                        'user_full_name'      => '',
                        'user_gender'         => ''                          
    ));

    $this->session->sess_destroy();
    redirect('default_controller');
}
krish_cloudnow
  • 180
  • 1
  • 13

1 Answers1

1

Perhaps you may wanna try the native PHP method: session_destroy();

if still doesnt work, try accessing the SESSION global and unset from there by using whatever method you please. (Eighter unset or re-set the variable value to null)

Miranda
  • 60
  • 9
  • Thanks a lot @Miranda. That solved my problem. Also I was running a javascript function called Logout() & was calling the controller their. I have now changed it and Logout is now a link which calls the Logout controller. – krish_cloudnow May 10 '15 at 14:12