Welcome Guest, Not a member yet? Register   Sign In
session problem
#1

[eluser]kosaidpo[/eluser]
heyy guys

im tryin to make a simple login
this is my model where i fetch the session data
Code:
function m_login(){
    
    $this->db->select('username' ,'password' ,'status') ;
    $this->db->from('users') ;
    $usr_login=array('username' => $this->input->post('username'),
                     'password' => $this->input->post('password')
                    ) ;
    $this->db->where($usr_login);
    $Q=$this->db->get();
    if($Q->num_rows == 1){
    
    $session_data=array('session_user'=> $this->input->post('username'));
                              //'status'      =>  1 ,
                             //'is_on'       => true) ;
    $this->session->set_userdata($session_data) ;
    return true ;
    }
    else{
    return false ;
    }
    
}


and here my contoller where i verify the session data but it seems it doesnt work cus when i remove the cookie it still go through the if stmt am i makin some mistakes ?? anynone can correct me tnx



Code:
function login(){
    
    if(!$this->forum_model->m_login()){
        echo 'login/mdp est incorrect' ;
    }
    elseif($this->_check_session()){
        echo'hello<b>'. $this->session->userdata('session_user').'</b> you\'re logged    in' ;
        }
        else{
        echo 'no' ;
        }
}

function _check_session(){
    
       $sess_user=$this->session->userdata('session_user') ;
        if(empty($sess_user)){
        return false ;
        }
        else{
        return true ;
        }
}

between is there any function or tip to verify the hole array session cus affectin evry variable with the session item its kinda not so good i find

tnx in advance
#2

[eluser]ciGR[/eluser]
I misunderstand what exactly you ask, so if you mean you have problem at this
Code:
if(!$this->forum_model->m_login()){
        echo 'login/mdp est incorrect' ;
    }else
...
...

every time this code runs, the session created from the m_login method, so and if you clean your cookies when you run the if statement, if the user exists in your database the $this->forum_model->m_login returns true.

I suggest you to restrict you model only with database operation and keep input, sessions in your controller.
#3

[eluser]kosaidpo[/eluser]
ohh yeah it looks so logic idk why ididnt notice nx dude

so now i shud call my check_session methode out of the login methode right when the check_session is called it ll run on her own without callin the login methode so it ll try to login again yeahh thats it i guess
tnx dude

and wht abt to verify the seesion data as in can i verify the hole asession-array
i dont like to verify item by item ??

tnx again
#4

[eluser]ciGR[/eluser]
For the last question you should save an array to your session, for example
Code:
$user = Array(
    'username'=>'ciGR',
    'password'=>'1234test'
    );        
$this->session->set_userdata('user',$user);

and for get the data in array you can use the
Code:
$user = $this->session->userdata('user');
print_r($user);//check the result
now you have again the array.
#5

[eluser]kosaidpo[/eluser]
if you didnt notice i use this in my code above : D but tnx what i look for is sumthin like this
Code:
foreach($this->sesion->userdata($data_session) as $elm){
if(empty($elm))
return false ;
}
but i've not tried this code and im not sure ill try it now well im lookin for sumthin like this instead of typin the same code and change the key index every time

i hope im enough clear

tnx
#6

[eluser]ciGR[/eluser]
I saw what you have in your code.
You have this
Code:
$this->session->set_userdata($session_data);

But I suggest you the

Code:
$this->session->set_userdata('user',$session_data);

In your code as you can see you get the values one at atime
with
Code:
$username = $this->session->userdata('username');
$passwod = $this->session->userdata('password');

But with the second way I tell you can get an array from your session.
Code:
$user = $this->session->userdata('user');

//and now check
foreach($user as $field):
    if(empty($field)):
       return false ;
    endif;
endforeach;

Hope to understand the difference.
#7

[eluser]kosaidpo[/eluser]
yeah dude i jst did Grr@me i dont kno where was my mind when i saw you sugges

tnx : D




Theme © iAndrew 2016 - Forum software by © MyBB