Reputation: 157
I have a login form with URL
index.php/Login
after login it shows me home page with same URl because i have called the view in index function of login controller. Now problem is when i click change password button it redirects to
index.php/Login/change_password
now if i called site_url('Login')
from change_password, it redirects me to login page but not back to user home page.
my Login controller code id below
public function index(){
$this->load->helper(array('form', 'url'));
$this->load->library('form_validation');
$this->load->database();
$this->form_validation->set_rules('email', 'Email', 'required|valid_email');
$this->form_validation->set_rules('password', 'Password', 'required');
if($this->form_validation->run() == FALSE){
$this->load->view('login');
}
else
{
$this->load->model('user_data');
$email = $this->input->post('email');
$data['info'] = $this->user_data->login_user($email, $this->input->post('password'));
$this->load->library('session');
$user = $data['info'];
$this->session->set_userdata($user);
$this->load->view('employee_main');
}
Any help will be greatly appricated.
Upvotes: 0
Views: 7904
Reputation: 13738
try to use session
first change:-
$this->session->set_userdata($user);
to
$this->session->set_userdata('myuser_session', $user); //giving a name to detect
Then check session is exist
public function index(){
$this->load->library('session');
if($this->session->userdata('myuser_session')) {
redirect(site_url());
}
Upvotes: 3