[eluser]Takapaka[/eluser]
Hi guys,
My problem is with a session that starts only at second attempt of login. Both in IE and Firefox. I tried to search for similar post but could not find it. Anybody had similar problem?
I can ask the guys who are rebuilding my page right now to look for a fix, but they will rip me off again
I am not a programmer myself but at least I think that this is the piece of code that starts the session in my page:
Code:
function trylogin($email, $password, $session = true)
{
log_message('debug', " +trylogin()");
if($email != '' && $password != '')
{
// Only continue if user and pass are supplied
// SHA1 the password if it isn't already
if(strlen($password) != 40){ $password = sha1($password); }
$sql = "SELECT userid FROM emails ".
"WHERE email ='$email'";
$query = $this->object->db->query($sql);
$query = $query->row();
$userid = $query->userid;
// Check details in DB
$sql = "SELECT name, surname FROM users ".
"WHERE userid = $userid ".
" AND password='$password' LIMIT 1";
$query = $this->object->db->query($sql);
// If user/pass is OK then should return 1 row containing username,fullname
$return = $query->num_rows();
log_message('debug', "++trylogin userid= ".$userid);
log_message('debug', "++trylogin return= ".$return);
log_message('debug', "++trylogin email= ".$email);
log_message('debug', "++trylogin password= ".$password);
if($return == 1)
{
$row = $query->row();
$username = $row->name . ' ' . $row->surname;
// Set session data array
$sessdata = array(
'userid' => $userid, // TODO fix it
'username' => $row->name,
'loggedin' => TRUE,
'fullname' => $username
);
if($session == true)
{
// Set the session
$this->object->session->set_userdata($sessdata);
return TRUE;
}
else
{// param to set the session = false:
// return the data only without setting session
return $sessdata;
}
}
else
{ // no rows with matching user & pass - ACCESS DENIED!!
return FALSE;
}
}
else
{
// missing username or password
return FALSE;
}
}