Welcome Guest, Not a member yet? Register   Sign In
Storing user information in SESSION
#1

[eluser]Unknown[/eluser]
Hi

I dive in CI and i thing it's great solution for wrighting CODE faster.
I have same questions.

-- usualy befor i start with CI i store SESSION data in $_SESSION[] like that

I make a query SELECT 8 FROM database WHERE userName = $usermane and userPass = $userpass

than i take the info from query and stored it to an array

$_SESSION['loged']=true;
$_SESSION['userInfo']=$result;

but i can;t find the solution in CI.

I made a costum data array with the post variables but i can't get furder to store the all information


in mw model i do this

Code:
function login(){

        $username = $this->input->post('userName');
        $userpass = $this->input->post('userPass');
        

        $this->db->where('userName',$username);
        $this->db->where('userPass',$userpass);
        $data = $this->db->get('users');
    

      
        if($data->num_rows()== 1){

            return TRUE;
        }
        
        
      
    }

and than in my Controler

Code:
function valid_login(){

        $this->form_validation->set_rules("userName","X",'required');
        $this->form_validation->set_rules("userPass","X",'required');

        if($this->form_validation->run()){

            $this->load->model('M_input');
            $result = $this->M_input->login();

            
            if($result){

                $user_data = array(

                    'is_loged' => TRUE,
                    'username' =>$this->input->post('userName'),
                  
                  
                );

              
              
                $this->session->set_userdata($user_data);
                $this->index();
            }

        }
        else{
            $this->index();
        }
    }

And it's work but

i trayed to take info from the $result variable but noting.

Show me the light Thank you
#2

[eluser]portgaz[/eluser]
Code:
function login(){

        $username = $this->input->post('userName');
        $userpass = $this->input->post('userPass');
        

        $this->db->where('userName',$username);
        $this->db->where('userPass',$userpass);
        $data = $this->db->get('users');
    

      
        if($data->num_rows()== 1){

            return TRUE;
        }
        
        
      
    }



its because that you did not return any values in your model.. you just set the return value to true..
#3

[eluser]portgaz[/eluser]
Im new to CI but I hope this will help.. Smile

in your model
Code:
function login(){

        $username = $this->input->post('userName');
        $userpass = $this->input->post('userPass');

        $this->db->where('userName',$username);
        $this->db->where('userPass',$userpass);
        $data = $this->db->get('users');
        
        if($data->num_rows() == 1)
            return $data->row_array();
        
        return FALSE;
    }

and in your controller
Code:
function valid_login(){

        $this->form_validation->set_rules("userName","X",'required');
        $this->form_validation->set_rules("userPass","X",'required');

        if($this->form_validation->run()){

            $this->load->model('M_input');
            $result = $this->M_input->login();

            if(!$result){
                $this->index();
            }else{
             $user_data = array(
                'is_loged' => TRUE,
                'username' =>$this->input->post('userName'),
              );

             $this->session->set_userdata($user_data);
             $this->index();
            }
        }
    }

and if you want to get the returned values from your database query using your model,
it's something like this..
Code:
$result['userName']; //for username
$result['userPass']; //for password

I hope that helps profesora...
#4

[eluser]InsiteFX[/eluser]
Read this article!

CodeIgniter Keeping it Dry

InsiteFX
#5

[eluser]portgaz[/eluser]
noted...

thanks InsiteFX.
#6

[eluser]Unknown[/eluser]
TH for the help but I have one more question=
This time is more trivial and is conect with CSS , images and index.php

I did everything i could find to make CSS work but it doesn't work. And everytime i try to make those .htaccess file work it bring me back Internal Server error 500




Theme © iAndrew 2016 - Forum software by © MyBB