Welcome Guest, Not a member yet? Register   Sign In
Issue about Session, can not set_userdata()
#1

[eluser]Nguyen The Nguyen[/eluser]
I'm using CI 2.02
I have a issue about session
very expect be the help

i have a model: user_model.php
Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class User_model extends CI_Model
{
    
    function checkuser_name($user_name){
    
        $sql =  "SELECT * FROM m4u_user WHERE user_name = '$user_name'";
        $query = $this->db->query($sql);
        if($query->num_rows() >0)
            return FALSE;
        else    
            return TRUE;
    }
    function checklogin(){
        $this->db->where('user_name', $this->input->post('user_name'));
        $this->db->where('user_password', md5($this->input->post('password')));
        $query = $this->db->get('m4u_user');
        
        if($query->num_rows == 1)
        {
            return true;
        }
    }

and controller: login.php
Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Login extends CI_Controller {
    
    public function todologin()
    {
        $this->load->model('user_model');
        $data['header'] = "LOGIN";
        $data['user_name'] = $this->input->post('user_name');
        
        if($this->user_model->checklogin()){
            $datauser = array(
            'username' => $this->input->post('username'),
            'is_logged_in' => true
            );
        $this->session->set_userdata($datauser);
            $data['content'] = "Login success";
            $this->load->view('success',$data);
            
        }
        else{
            $data['re_error'] = "username or password not incorrect";
            $this->load->view("formlogin",$data);
        }
    }
}

view is form_login, sent info to
Code:
<?=form_open('login/todologin');?>
result when login success is
Code:
A PHP Error was encountered

Severity: Warning

Message: Cannot modify header information - headers already sent by (output started at C:\AppServ\www\M4U\application\models\user_model.php:2)

Filename: libraries/Session.php

Line Number: 671

very expect be the help
thanks
#2

[eluser]InsiteFX[/eluser]
That error usally means you have whitespace before the php tag or the ending php tag!

InsiteFX
#3

[eluser]toopay[/eluser]
Thats mean check if there are
Code:
<-- This is whitespace
&lt;?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class User_model extends CI_Model
...
#4

[eluser]Nguyen The Nguyen[/eluser]
Smile , OK, very thank for InsiteFX and toopay
#5

[eluser]tenantfile[/eluser]
it only uses the php.But if session failed in Asp then this same process will not work.




Theme © iAndrew 2016 - Forum software by © MyBB