Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CodeIgniter function to clear session

If i uncomment this code, i get blank page at site. If i comment this, site works. Here is my exit code (auth by sessions):

    function exit($action='') {
    if ($action == "true") {
        echo "Exit.";
        return;
    }
    $login = $this->session->userdata('username');
    if ($login == NULL) {
        redirect('/blog/login/', 'location', '301');
    }
    $array_itmes = array('username' => "$login");
    $this->session->unset_userdata($array_items);
    redirect('/blog/exit/true/', 'location', '301');}

after normal login:

    $newdata = array('username' => "$name");
    $this->session->set_userdata($newdata);

in other actions i using:

    $login = $this->session->userdata('username');
    if ($login !== NULL) {
        echo $login;
    }

and I get my username. where is an error in first code? i`m from Russia, so sorry for bad English.

like image 529
kopaty4 Avatar asked Feb 14 '26 04:02

kopaty4


2 Answers

Just replace it with $this->session->sess_destroy();

like image 166
kopaty4 Avatar answered Feb 16 '26 19:02

kopaty4


$array_val = array('userid' => '','username' => '', 'email' => '');

$this->session->unset_userdata($array_val);

This is remove individual session details.

like image 34
Sumith Harshan Avatar answered Feb 16 '26 17:02

Sumith Harshan