I am trying to direct the user to my main page when the user is authorized. I am doing the user check in my login_check controller and add $this->load->view('main'); The page can be load but the site address in the main page still show

but I want it to show

.

Do i have to create a new 'main' controller and load the view? It sounds redundant to me. Here is my code.

part of my login_check.php

private function _user_check() { $this->load->model('user_query'); //load my model $result=$this->user_query->query($this->input->post('username'),$this->input->post('password')) if($result) //the user is in DB { $data['view']='main'; $this->load->view('include/template', $data); //the address bar shows in main page }else{ //the user is not in DB $data['view']='login'; $this->load->view('include/template', $data); } } 

3 Answers

First of all, you are doing a very poor job of checking if the user is authenticated (just passing username/pass to model isn't best, should process / check it before sending to model).

You can make redirects easily by including the helper 'URL' and simply use:

redirect('/controller/method'); 

or in a real world example:

redirect('/main'); 

Reference Link

7

There is another way but similar to redirect(), if your controller is Rest controller

restserver

You can use rest client in another controller to call methods on the server controller

restclient

redirect('controller/function'); 

For example you can have redirect('auth/login'); with routes as

$route['auth/login'] = 'auth/auth/index'; 

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy