Welcome Guest, Not a member yet? Register   Sign In
having problems with session_start
#1

[eluser]Unknown[/eluser]
I am reading the CI book by Wrox and am going through the sample code. Everything was goiing fine until I was in Chpater 6, where I had to run through a native PHP session to construct an administrator login. Copied the code, tried it but I get an error indicating that the session variables I had assigned value with in my models does not exist. Here are the main points:

The Controller:
Code:
$user = $this->input->post('username');
$password = $this->input->post('password');
$this->MAdmins->verifyUser($user, $password);
if($_SESSION['userid'] > 0)
{
    redirect('admin/dashboard');
}

The Model:
Code:
//perform database query
$this->db->select('id','username');
$this->db->where('username', $user);
$this->db->where('password', $pass);
$this->db->where('status', 'active');
$this->db->limit(1);
$query = $this->db->get('administrator');

//perform result verification and assign to session variables
if($query->num_rows() > 0)
{
        $row = $q->row_array();
    $_SESSION['userid'] = $row['id'];
    $_SESSION['username'] = $row['username'];
}

The View:
Code:
<?php
echo form_open('administrator/login');
echo form_label('Username','username');
$udata = array(
    'name' => 'username',
    'id' => 'username',
    'size' => 40
);
echo form_input($udata) . '<br/>';

echo form_label('Password', 'password');
$pdata = array(
    'name' => 'password',
    'id' => 'password'
);
echo form_password($pdata) . '<br/>';
echo form_submit('submit', 'Submit');
?&gt;
&lt;/form&gt;


I am getting an error undefined index : userid or undefined index: username

I have started the session via:

Code:
function Administrator()
{
    parent::Controller();
    session_start();
}

What could I be doing wrong?


Messages In This Thread
having problems with session_start - by El Forum - 06-19-2009, 11:39 PM
having problems with session_start - by El Forum - 06-20-2009, 03:57 AM
having problems with session_start - by El Forum - 06-21-2009, 05:15 AM



Theme © iAndrew 2016 - Forum software by © MyBB