Azure1015 Azure1015 - 1 year ago 216
PHP Question

CodeIgniter 3.0.6 Redirect function does not work correctly

I am an absolute beginner of web development. I am using CodeIgniter framework right now.

I have been following the tutorial above so far. When watching part 6, I have an issue with redirect function in the login function below.
The redirect function should load to index/home, but it actually does not. It goes to user/login and the application says that the requested page does not exist.

Has anyone ever encountered a similar problem below? If you have, please leave your comments!
English is not my first language, so if this post does not make sense or you need more information, please let me know as well.
Any advice would be appreciated! Thanks in advance!


public function login(){
$this->form_validation->set_rules('username', 'Username', 'trim|required|min_length[4]');
$this->form_validation->set_rules('password', 'Password', 'trim|required|min_length[4]|max_length[50]');

if($this->form_validation->run() == FALSE){
// nothing
} else{
// get from post
$username = $this->input->post('username');
$password = $this->input->post('password');

// get user id from the model
$user_id = $this->User_model->login_user($username, $password);

// validate user
// create array of user data
$user_data = array(
'user_id' => $user_id,
'username' => $username,
'logged_in' => true

// set session data

$this->session->set_flashdata('login_success', 'You are now logged in');

// set error
$this->session->set_flashdata('login_failed', 'Sorry the login info that you entered is invalid');


Answer Source

try adding "/" before the url

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download