How do i redirect the user into current page after login?
User is reading a news at this URL
domain.com/article/news-18565
once he click the login button then how do i get currenturl() before going todomain.com/login
and after login user should go todomain.com/article/news-18565
Form.html
<form action="signin" method="post" accept-charset="utf-8">
<div class="form-group">
<label for="">Email:</label>
<input type="text" name="email" value="" class="form-control form-control-lg">
</div>
<div class="form-group">
<label for="">Password:</label>
<input type="password" name="password" value="" class="form-control form-control-lg">
</div>
<div class="form-group">
<input type="submit" name="submit" value="Sign in to your account" class="float-md-right btn btn-primary">
</div>
</form>
Controller.php
function index(){
$user_profile = 'user';
$this->authModel->loggedin() == FALSE || redirect($user_profile);
$rules = $this->authModel->rules;
$this->form_validation->set_rules($rules);
if($this->form_validation->run() == TRUE){
if($this->authModel->login() == TRUE){
redirect($user_profile);
}else{
$this->session->set_flashdata('error', 'That email/password combination does not exist');
redirect('signin');
}
}
}
Model.php
function login(){
$user = $this->get_by(array(
'email' => $this->input->post('email', TRUE),
'password' => $this->hash($this->input->post('password'))
), TRUE);
if(count($user)){
$data = array(
'name' => $user->name,
'email' => $user->email,
'username' => $user->username,
'loggedin' => TRUE
);
$this->session->set_userdata($data);
return TRUE;
}
}