1
votes

After I remove index.php, I enable query string in codeigniter . But I have some trouble with redirect link. Detail , I have login form (login/index) and when login success redirect to "welcome/index" and save email in session .

But when login success only load view of "welcome/index" and wrong link , now link is : "?login/index" And session don't save . Please help me .

Here's my code

Login.php (Controller)

if($this->input->post('email') != '' && $this->input->post('password') != ''){
        if ($this->user->CheckLogin($this->input->post('email'),$this->input->post('password')) == true)
        {
            $this->load->library('session');
            $this->session->set_flashdata('email', $this->input->post('email'));
            redirect('welcome/index', 'refresh');
        }
        else
        {
            $data['error_message'] = '* Email or Password is incorrect';
            $this->load->view('login',$data);
        }
    }else{
            $this->load->view('login',$data);
    }

Welcome.php (Controller)

class Welcome extends CI_Controller {

public function index()
    {
         $this->load->model('user');
         $this->load->helper('url');
         $this->load->library('session');

         $data['email'] = $this->session->flashdata('email');
         $this->load->view('welcome_message',$data);
    }
}

welcome_message.php (View)

<?php 
    // Cant print email
    echo $email; 
?>

.htaccess

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
1
On your config.php have you made $config['uri_protocol'] = 'QUERY_STRING';Mr. ED
Thanks . It's working but all my link have "?" character . Example : ?welcome/index , ?login/index . Why's that :(jonny
Could be due to your htaccess file in main directory if have any.Mr. ED
I just update .htaccess file you can check for me . Thanks :)jonny
Did you by any chance $config['enable_query_strings'] = FALSE; or is it set to TRUEMr. ED

1 Answers

0
votes

If you enable Query Strings then change the redirect like this

redirect('c=welcome &m=index', 'refresh');

Additionally it may required to write index.php? or only ? before c

Or if change configuation in config.php then you need change the c and m like

$config['enable_query_strings'] = FALSE;
$config['controller_trigger'] = 'c';
$config['function_trigger'] = 'm';

for more info http://www.codeigniter.com/user_guide/general/urls.html#enabling-query-strings