Welcome Guest, Not a member yet? Register   Sign In
Session library fails to load
#1

[eluser]cybiko123[/eluser]
Hi,

I've tried the standard CodeIgniter session library and the native session library, both to no avail. In both cases, I get:

Message: Undefined property: Login::$session

I've tried autoloading the library and loading it explicitly ($this->load->library('session')), and neither work.

Am I doing something wrong?
#2

[eluser]bobbob[/eluser]
I think you might not be using Codeigniter's session library correctly.
like:
Code:
$this->session->set_userdata('some_data');//set it
$this->session->userdata('some_data');//get it

http://ellislab.com/codeigniter/user-gui...sions.html
#3

[eluser]cybiko123[/eluser]
I looked at the user guide again, and came back with two versions:

Code:
$this->session->set_userdata('some_name', 'some_value');

and

Code:
$newdata = array(
                   'username'  => 'johndoe',
                   'email'     => '[email protected]',
                   'logged_in' => TRUE
               );

$this->session->set_userdata($newdata);

I tried both versions (copy/pasted directly from the user guide) and got the same error.
#4

[eluser]bobbob[/eluser]
Can you show your controller?
#5

[eluser]cybiko123[/eluser]
Sure:

Code:
<?php

class Login extends Controller {

function index()
{
        $this->load->library('session');
//        $this->load->database();

    if($_POST)
    {
        $this->load->helper('url');
        $username = $this->input->post('username');
        $password = $this->input->post('password');
        
        $query = $this->db->query("SELECT password FROM users WHERE username = '$username' AND LENGTH(username) > 0 AND LENGTH(password) > 0");
        
        $results = $query->result();
        
        if(count($results) > 0)
            {
                $correctPass = $results[0]->password;
                if(md5($password) == $correctPass)
                    {
                        $this->session->set_userdata(array('username' => $username, 'password' => $correctPass));
                        redirect("/");
                    }
                else
                    {
                        redirect("/login");
                    }
            }
        else
            {
                redirect("/login");
            }
    }
    
    else
    {
        $this->load->helper('form');
        $form = form_open('login');
        $form .= '<table border="0"><tr><td>User name: </td><td>';
        $form .= form_input('username');
        $form .= '</td></tr>';
        $form .= '<tr><td>Password: </td><td>';
        $form .= form_password('password');
        $form .= '</td></tr><tr><td>&nbsp;</td></tr><tr><td>';
        $form .= form_submit('', 'Log in');
        $form .= '&nbsp;';
        $form .= form_reset('', 'Clear');
        $form .= ('</td></tr></table>');
        $form .= form_close();
        $this->load->view('login', array('form' => $form));
    }

}


}

?&gt;
#6

[eluser]bobbob[/eluser]
try changing this
$results = $query->result(); to $results = $query->row();
and
$results[0]->password; to $results->password;
#7

[eluser]cybiko123[/eluser]
No dice. Got the exact same error.
#8

[eluser]bobbob[/eluser]
I see the database is commented out.
Is it auto-loading?
#9

[eluser]cybiko123[/eluser]
It was at one point. Good catch.

Unfortunately, that didn't change the error. I tried print_r()ing the array that was being passed to set_userdata, and it seems to contain the data I want to pass to set_userdata().
#10

[eluser]bobbob[/eluser]
ok this should be it:
in the controller you need this function:

function Login()
{
parent::Controller();
}




Theme © iAndrew 2016 - Forum software by © MyBB