Welcome Guest, Not a member yet? Register   Sign In
Can't destroy session
#11

[eluser]Yunus Khan[/eluser]
hmm.

Suppose you have a library session.php. Now write

Code:
function destroy()
{
  unset($_SESSION);
  if ( isset( $_COOKIE[session_name()] ) )
     {
         setcookie(session_name(), '', time()-42000, '/');
     }
   session_destroy();
}

Then you write your controller page
Code:
function logout()
{
   $this->obj->session->destroy();
   redirect('Login/logout', 'location');
}
#12

[eluser]webthink[/eluser]
$_SESSION is a global for use with PHP's native sessions. CI's session handler makes no use of native sessions.
Unless you're using a third party library that makes use of PHP's native sessions (as opposed to cookie+db or CI's default cookie only approach) *or* you're making use of it by writing directly to $_SESSION in your application (and therefore bypassing use of a session handler) Then doing *anything* to destroy $_SESSION will have no effect.
#13

[eluser]adamp1[/eluser]
Seriously try my method, has worked for me, then it uses the session libraries implementation to destroy the session.
#14

[eluser]webthink[/eluser]
adamp1, You're method will certainly work. I'm just not sure why it's necessary. If you expire the cookie you have effectively done everything a logout function needs to do. The cookie will be recreated on the very next request (if there is one). If the user navigates away from the site the cookie will be destroyed when the browser closes.
Effectively the problem that the OP reports is not actually a problem.
#15

[eluser]steelaz[/eluser]
Thanks, my problem was that after destroying session, logout function would call another function in a controller. I just changed it from local call to redirect and works fine now.

Now I didn't try adams code, but it looks like it would have worked for me too. Creating new session would unset all the old values.
#16

[eluser]Tiến Thành[/eluser]
I had the same problem, so i fixed issue by creating a function in libray folder:
Code:
class Auth_lib{
public function do_logout(){
        $CI =& get_instance();
        $CI->session->sess_destroy();
        redirect ('linit/login');
    }
}

and then function logout in controller, i call this do_logout function:
Code:
public function logout(){                  
        $this->auth_lib->do_logout();      
    }


and result is session were destroyed.

#17

[eluser]skunkbad[/eluser]
[quote author="Tiến Thành" date="1343445516"]I had the same problem, so i fixed issue by creating a function in libray folder:
Code:
class Auth_lib{
public function do_logout(){
        $CI =& get_instance();
        $CI->session->sess_destroy();
        redirect ('linit/login');
    }
}

and then function logout in controller, i call this do_logout function:
Code:
public function logout(){                  
        $this->auth_lib->do_logout();      
    }


and result is session were destroyed.

[/quote]

Maybe this is your problem:

https://github.com/EllisLab/CodeIgniter/...0693774273
#18

[eluser]Tiến Thành[/eluser]
[quote author="skunkbad" date="1343446935"][quote author="Tiến Thành" date="1343445516"]

Maybe this is your problem:

https://github.com/EllisLab/CodeIgniter/...0693774273[/quote]

Thanks skunkbad, but i use files in this above file (library, controller) to fixed destroy session problem.

Can you help me set/delete cookie? I use
Code:
delete_cookie("name");
, but it's not working.




Theme © iAndrew 2016 - Forum software by © MyBB