Ranjith M Ranjith M - 3 months ago 10
PHP Question

What to do with session on updating the information

i'm using codeignitor 3 and for login purpose i'm using session, like on successful authentication i'm saving username, password. profile_pic, etc everything on a session. now in want to know that if we are updating the informations that we stored in the session like profile_pic, name , address how to change the session, means i want to know the best solution for this, do i need to logout on successfull updation or i have to update the session values , Please help me :-)

if($result){
$this->session->set_flashdata('success', 'User Added Successfully.');
redirect(base_url().'settings/editaccount','refresh');
$this->session->set_userdata('image','testing.png');
}else{
$this->session->set_flashdata('error', 'User Added Unsuccessfully.');
redirect(base_url().'settings/editaccount','refresh');
}

Answer

If you want to update the session data, use:

$this->session->set_userdata('image','testing.png');

use it before redirect like this

 if($result){
            $this->session->set_flashdata('success', 'User Added Successfully.');
            $this->session->set_userdata('image','testing.png');
            redirect(base_url().'settings/editaccount','refresh');

        }else{
            $this->session->set_flashdata('error', 'User Added Unsuccessfully.');
            redirect(base_url().'settings/editaccount','refresh');
        }