ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

User Login

November 02, 2009 7:37pm

Subscribe [4]
  • #16 / Nov 03, 2009 9:37pm

    clip

    72 posts

    did work man here my code

    function checkLogin()
        {
        
            $this->load->helper('cookie');
                
            $u1 = get_cookie('username');
            $p1 = get_cookie('password');
    
            $logged = $this->db->get_where('users', array ('username' => $u1, 'password' => $p1));
    
            if($logged->num_rows() > 0)
            {
                 $row = $query->row();
    
                 $uId = $row->id;
                 $uName = $row->username;
                
                $data['userId'] = $uId;
                $data['userName'] = $uName;
                
                return $data;
            } 
        }

    To get access to your returned data you need to do in your controller

    $userdata = $this->model_name->checkLogin();
    if($userdata)
    {
        echo $userdata['userId'];
        //or assign it to another variable to use later in your view
       
    }

    Also to make things cleaner instead of returning just the $data array you could

    return $row;
    //instead of 
    return $data
    
    //then you have access to the entire query result
    //from your controller you would then do
    $userdata = $this->model_name->checkLogin();
    if($userdata)
    {
        echo $userdata->table_field_name;
        //or assign it to another variable to use later in your view
       
    }
  • #17 / Nov 04, 2009 5:28pm

    GamingFusion

    97 posts

    ok thanks man that makes sense

  • #18 / Nov 04, 2009 8:55pm

    GamingFusion

    97 posts

    still nothing

    heres my function that im use to get the variables to display

    function index()
        {
            //then you have access to the entire query result
            //from your controller you would then do
            $userdata = $this->database->checkLogin();
            if($userdata)
            {
                $data['uId'] = $userdata->id;
                //or assign it to another variable to use later in your view
       
            } 
            
            $data['title'] = 'Theater 311';
            $data['heading'] = 'Welcome to Theater 311';
            
            $this->load->view('main', $data);
        }

    The title and heading variables work but not uId

  • #19 / Nov 04, 2009 9:01pm

    jedd

    2089 posts

    The title and heading variables work but not uId

    This might be how to suck eggs stuff, but when you say ‘not uId’ it’s unclear what you’ve done.

    Obviously the first thing would be an echo ‘hi!’ in your if {} block, just to prove out you’re getting past the conditional.  Or even a var_dump.

    I’d like to assume you’ve already done this, as it’s pretty basic PHP debugging stuff - but if you had, then you’d have solved your problem already I think.

  • #20 / Nov 05, 2009 5:22pm

    GamingFusion

    97 posts

    theres something wrong with the login script.

    The Login script isn’t checking anything

    function login()
        {
            $this->load->helper('cookie');    
        
            $username = $this->input->post('username');
            $password =  $this->input->post('password');
            
            $checkUser = $this->db->get_where('users', array('username' => $username, 'password' => $password));
            
            if ($checkUser == FALSE) {
                
                echo 'Password is incorrect.';
                
            }else{
                
                    $cookie = array(
                       'username'   => $username,
                       'passdword'  => $password,
                   );
    
                    set_cookie($cookie);
                    
                    redirect('theater', 'refresh');
            }        
        }
  • #21 / Nov 05, 2009 6:05pm

    clip

    72 posts

    try changing this…

    if ($checkUser == FALSE) {
                
                echo 'Password is incorrect.';
                
            }else{
               ....................

    to

    if ($checkUser->num_rows() < 1) {
                
                echo 'Password is incorrect.';
                
            }else{

    again this is in the link I suggested you read about generating query results.

    Edit: It appears it isn’t being checked because get_where() returns an array of objects regardless of the number of rows fetched by your query.

  • #22 / Nov 05, 2009 7:41pm

    GamingFusion

    97 posts

    ok something is wrong im being redirected to the home page but none of the variables work

    function login()
        {
            $this->load->helper('cookie');    
        
            $username = $this->input->post('username');
            $password =  $this->input->post('password');
            
            $checkUser = $this->db->get_where('users', array('username' => $username, 'password' => $password));
            
            if ($checkUser->num_rows() < 1) {
                
                echo 'Password is incorrect.';
                echo $password;
                
            }else{ 
                          $cookie = array(
                       'username'   => $username,
                       'passdword'  => $password,
                       );
    
                    set_cookie($cookie);
                    
                    redirect('theater', 'refresh');
            
            }        
        }

    the login page directs me to the home like it should if the variables have values

    heres the checkLogin() function

    function checkLogin()
        {
        
            $this->load->helper('cookie');
                
            $u1 = get_cookie('username');
            $p1 = get_cookie('password');
            
            
            $logged = $this->db->get_where('users', array ('username' => $u1, 'password' => $p1));
    
            if($logged->num_rows() >0)
            {
                 $row = $logged->row();
    
                 $uId = $row->id;
                 $uName = $row->username;
                
                $data['uId'] = $uId;
                $data['uName'] = $uName;
                
                echo $u1;
                
                return $row;
            } 
        }

    what i changed in here was

    $query = $this->db->get_where(‘users’, array (‘username’ => $u1, ‘password’ => $p1));

    to

    $logged = $this->db->get_where(‘users’, array (‘username’ => $u1, ‘password’ => $p1));

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases