I am using the following codes to redirect my user to previous page after a particular task is done.
if (isset($_SERVER['HTTP_REFERER']))
{
$this->session->set_userdata('previous_page', $_SERVER['HTTP_REFERER']);
}
else
{
$this->session->set_userdata('previous_page', base_url());
}
The above code I use in a controller and the following code in another controller..
.... some other stuffs... I am updating database values here....
$this->db->where('t_expenseid', $t_expenseid);
query=$this->db->update('teacherexpense', $data);
redirect($this->session->userdata('previous_page'));
The above code is working fine but the problem I am facing is I want to send a success message with the redirect so that when the previous page loads a success message pops up (I already have jquery for that). And for this I added the following code above the redirect, but I don't know how to send the $data or the message along with the redirect. And if I am able send it how to retrieve the value in the controller of the previous page.
$data['msg']='Information Has been Successfully Inserted';
Could you please tell me how to send it and then retrieve it?
Thanks :)
You can use set_flashdata of CI.You can use only once that message after refresh page message goes blank.
$this->session->set_flashdata('message', 'Authentication failed');
redirect(site_url('message/index/'), 'refresh');
And on that page you can catch this message by
$message = $this->session->flashdata('message').