I have login controller in my CI app:
function index()
{
if($this->session->userdata('logged_in')==TRUE)
redirect('/success');
$data['error']=$this->session->flashdata('errormessage');
$this->load->view('auth',$data);
}
function process_login()
{
$username=$this->input->post('username');
$password=$this->input->post('password');
if($password == "good_pwd")
{
$data=array('username'=>$username,'logged_in'=>TRUE);
$this->session->set_userdata($data);
redirect('/success');
}
else
{
$this->session->set_flashdata('errormessage','Login failed');
redirect('/failed');
}
}
Thats my securing constructor in main controller:
function __construct()
{
parent::__construct();
if($this->session->userdata('logged_in')!=TRUE) redirect('/login');
}
When I’m trying to get into http://www.mysite.com/main/function1/ and I’m not logged in, then constructor redirects me into login page – when I log in correct I’m being redirected into main home page instead of page which redirected me into login page (in this example case: http://www.mysite.com/main/function1/ ) – how to do it?
you’d need to store your request URI in a session for this, so you can return to the previous page, something along the lines of:
… you can then use session data to redirect back