Welcome Guest, Not a member yet? Register   Sign In
[resolved]cannot start session , no empty space before <?php , help needed
#1

[eluser]johansonevR[/eluser]
It worked with other scripts why does it not work now i hope to resolve.
here is the code from my controller
Code:
Class Login extends Controller{
    
    function Login(){
        parent::Controller();
        $this->load->library('session');
        $this->load->helper('url');
        $this->load->helper('form');
        $this->load->library('form_validation');
        $this->load->model('login_model');
        }
    function index(){
        $rules=array(
                    array(  'field'=>'username',
                            'label'=>'username',
                            'rules'=>'required|alpha_numeric|min_length[3]|xss_clean'
                        ),
                    array(    'field'=>'password',
                            'label'=>'password',
                            'rules'=>'required|alpha_numeric|min_length[6]|xss_clean'
                        )
                );
        $this->form_validation->set_rules($rules);
        if($this->form_validation->run()==TRUE){
        $data=array('username'=>$this->input->post('username'),
                    'password'=>$this->input->post('password')
                    );
            $message['output']=$this->login_model->checkLogin($data);
            $this->load->view('login_success',$message);
            //test
            print($this->session->userdata('name'));
        
        }else{
            $this->load->view('login_view');
            }
    }
}
And here is the code from my model where i set the session variables.
Code:
class Login_model extends Model{
    function Login_model(){
        parent::Model();
        $this->load->library('session');
        
        }
    function checkLogin($data){
        $query=$this->db->query("SELECT * from users where username='".$data['username']."' ");
            if($query->num_rows()<1){
                $error['username']= "wrong username";
                return $error;
                }else{
                $query=$this->db->query("SELECT * from users where username='".$data['username']."' AND password='".$data['password']."';");
                    if($query->num_rows()<1){
                        $error['password']= "wrong password";
                        return $error;
                        }
                    }
        $row=$query->row();
        $loged_in=array('name'=>$row->fname." ".$row->lname,
                        'email'=>$row->email,
                        'phone'=>$row->phone,
                        'username'=>$row->username
                        );
        
            $this->session->set_userdata($loged_in);
        
        
            
                
    }
    
}
Everything seems fine to me can someone pls tell me what is wrong.
When i execute it i get the error
Quote:A PHP Error was encountered

Severity: Warning

Message: Cannot modify header information - headers already sent by (output started at \project\system\application\controllers\login.php:1)

Filename: libraries/Session.php

Line Number: 662
i can't understand what is wrong it worked with other scripts
pls provide some info on which i can fix this.
tnx.
#2

[eluser]rogierb[/eluser]
The 'headers already sent by (output started at \project\system\application\controllers\login.php:1)'
might indicate that you have a space or an empty line on the first line before &lt;?php

Could you check that?
#3

[eluser]johansonevR[/eluser]
i checked it.
it looks like it is from somewhere else.
#4

[eluser]Sbioko[/eluser]
1) Why do you load your session library twice? In controller and model?
2) Tell your file's encoding.
#5

[eluser]johansonevR[/eluser]
heh loading it once then.
i've been changing the encodings in my files from ANSI to UTF-8. Who would have known it inflicts so much complications. I've changed it back to ANSI and all runs well now. Tnx for your help, bye bye.




Theme © iAndrew 2016 - Forum software by © MyBB