Welcome Guest, Not a member yet? Register   Sign In
Using sessions and cookies
#1

[eluser]Ci beginner[/eluser]
Hey there!

I'm looking over the CI sessions, but it seems there's no option to do what I need, that is... I always need to get an array with the user information. I try to explain.

I'm currently using a template - like do_header(), do_footer()... - for my website. It loads in every view. I need that user information as soon as CI starts up, so I'd like to make a query to the database to get the user information from the SSID taken from the cookie of the user.

In resume, the steps:

1. User reachs website and send cookie (if exists)
2. System takes the value of the cookie and query DB to get user info.
3. If exists, we set a global array to be used in every view with the user info.

And my question is: where to put the step 2? and also, how do you recommend to set the global array for this kind of things (or may I use $_SESSION)?

Thank you in advance!
#2

[eluser]David Johansson[/eluser]
Why not set the user information in the cookie/session to start with?
#3

[eluser]Ci beginner[/eluser]
[quote author="David Johansson" date="1248759614"]Why not set the user information in the cookie/session to start with?[/quote]

Yes, that's the thing I'm trying to do! Sorry for my bad English. Actually I'm using the sessions CI library (with encryption, in the other hand). You know, when some user enter to your site, a query is performed to the database. If doesn't exists, it creates a session in the table of sessions. If not, it update it.

However, I see there's a user_info TEXT in the DB to put the data of the user. That's the point! If the session exists, I want to get the user information for that user, and put in user_info.

What can I do? I'm checking http://ellislab.com/codeigniter/user-gui...sions.html but I don't find the solution.

Thank you!
#4

[eluser]David Johansson[/eluser]
I don't think there is any user_info in the db, but it is a field called user_data. To set a value there use the command
Code:
$this->session->set_userdata('username', $username);
then you can reciev the data on every page using
Code:
$username = $this->session->userdata('username');
you should check the the user guide, the solution is indeed on there Smile
#5

[eluser]Ci beginner[/eluser]
[quote author="David Johansson" date="1248762882"]I don't think there is any user_info in the db, but it is a field called user_data. To set a value there use the command
Code:
$this->session->set_userdata('username', $username);
then you can reciev the data on every page using
Code:
$username = $this->session->userdata('username');
you should check the the user guide, the solution is indeed on there Smile[/quote]

I think I get it, thank you very much!




Theme © iAndrew 2016 - Forum software by © MyBB