CodeIgniter Forums
Help session grab user_id from database - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Help session grab user_id from database (/showthread.php?tid=51925)

Pages: 1 2 3 4 5


Help session grab user_id from database - El Forum - 05-23-2012

[eluser]weboap[/eluser]
whats in line 115 and 149 in your user.php ???


Help session grab user_id from database - El Forum - 05-23-2012

[eluser]the_unforgiven[/eluser]
Found it, thought it was strange is wasn't doing this:

Code:
$this->session->set_userdata($data);
redirect('user/myaccount');

So in actual fact is was setting in the db has i checked that first then i got the white page, and thought something else was wrong so by adding those 2 lines in all has worked fine.

Much appreciated everyone's contributions, thanks a million guys the forum rules!!!


Help session grab user_id from database - El Forum - 05-23-2012

[eluser]the_unforgiven[/eluser]
Come across another problem now:

When i logging with test/test has a customer which the id in the database is 15 which gets stored (or so i thought in the session) then log out the log out function unset's all user data for the session and does a session destroy too.
then i log in with me/me has the customer it shows me logged in but when i got to other details like account number and things i've set in the session it still shows has the test/test user is logged in.

Any idea's why this is have i missed something or not understanding... Sad


Help session grab user_id from database - El Forum - 05-23-2012

[eluser]the_unforgiven[/eluser]
Anyone?


Help session grab user_id from database - El Forum - 05-24-2012

[eluser]the_unforgiven[/eluser]
Please someone?


Help session grab user_id from database - El Forum - 05-24-2012

[eluser]Ed Robindon[/eluser]
Hello,

I use the native PHP $_SESSION for session.

When a user successfully logs in I simply store the database row in a
session variable and all user info is available anywhere I need it.

Code:
$row = $query->row();
      //Validation code removed...
      $_SESSION['user']=$row;
      $_SESSION['loggedin'] = true;

Does this help any?

Ed


Help session grab user_id from database - El Forum - 05-24-2012

[eluser]the_unforgiven[/eluser]
That's pretty much how it works now using what is stated in previous posts, but its leaving one user logged in instead of the new one i'm logging in has.


Help session grab user_id from database - El Forum - 05-24-2012

[eluser]Ed Robindon[/eluser]
Correct me if I'm wrong but each user gets their own set of session variables...


Help session grab user_id from database - El Forum - 05-24-2012

[eluser]the_unforgiven[/eluser]
yes thats my problem, its not doing has it should be


Help session grab user_id from database - El Forum - 05-24-2012

[eluser]Samus[/eluser]
[quote author="the_unforgiven" date="1337876219"]That's pretty much how it works now using what is stated in previous posts, but its leaving one user logged in instead of the new one i'm logging in has.[/quote]
I think it's because you need to make your model method more 'dynamic'

As it is now

Code:
function getCustomer()
{
   $data = array();
   $options = array('id' => 14);
   $Q = $this->db->get_where('users',$options,1);
   if ($Q->num_rows() > 0){
        $data = $Q->row_array();
   }
     $Q->free_result();    
     return $data;
}

It's only searching for the user with id = 14.

Hope that helps. Smile