I have this function
public function logout() {
if ($this -> user_model -> is_logged() === TRUE) {
$user_id = $this -> user_model -> get_id();
if (get_cookie('cookie_name') != FALSE) {
delete_cookie('cookie_name');
$new_cookie = md5(sha1(rand() . time() . $user_id));
$this -> db -> set('cookie', $new_cookie);
$this -> db -> update('users') -> where('id = ' . "'" . $user_id . "'");
}
$this -> session -> unset_userdata('user_id');
echo "logged out? <a href=" . base_url() . ">click here</a>";
} else {
echo "no";
}
}
when
if (get_cookie('cookie_name') != FALSE) {
is true and the code inside the if brackets is executed then the other two lines of code:
$this -> session -> unset_userdata('user_id');
echo "logged out? <a href=" . base_url() . ">click here</a>";
While when the if code doesn’t get executed these lines are executed correctly.
The code inside if is correctly executed because then the cookie is deleted and the database updated.
I’m using Codeigniter 2.1.0 but I don’t think the issue is releated to this.
My php version is 5.3 under localhost on Ubuntu 11.04
As I commented above, your updates statement needs to be seperated out. You need to chage this line:
to this:
Be aware that the where clause is “emptied” after the update statement and if you plan on doing more than one update in the future then you will have to repeat the where clause.