Welcome Guest, Not a member yet? Register   Sign In
Sessions Question / Extending the CI_Session class?
#1

[eluser]Clooth[/eluser]
Hey,

First of all, as this is my first post that I'm posting, I'd like to say I'm really glad CodeIgniter exists with such an active & helpful community. Smile

Anyway, I was wondering how I could be able to get functionality for the sessions class, that when the data is sent to the database, I could add in custom data that would be added into another field in the table in the database, in my case the 'User ID' would be along the user_ident and ip_address and such.

Is there functionality like this in CI or do I have to work out some hyper-magic-hacks to achieve this?

Thanks in advance,
Nico

Edit: I found an $userdata array in the Session.php file, I'm wondering if it's related, well obviously it is but not sure how I would go to editing it since I can't pass parameters to the sess_create() function. :/ *thinks*
#2

[eluser]Georgi Veznev[/eluser]
Hi,
Session Class

Quote:Adding Custom Session Data

A useful aspect of the session array is that you can add your own data to it and it will be stored in the user's cookie. Why would you want to do this? Here's one example:

Let's say a particular user logs into your site. Once authenticated, you could add their username and email address to the session cookie, making that data globally available to you without having to run a database query when you need it.

To add your data to the session array involves passing an array containing your new data to this function:
$this->session->set_userdata($array);
Greetings!
#3

[eluser]Clooth[/eluser]
That does not store the information in the database, however.

I need a way to add new fields to the "ci_sessions" database table "prototype", so I can wind through the database and see who's online and such.
#4

[eluser]Georgi Veznev[/eluser]
Have you tested it?

When you use :

Code:
$this->session->set_userdata($array);

The function serializes the array and stores it in the user_data field in the sessions table. (So the data is in the DB)

If you want to have other(custom) fields in the DB - I think there was some sort of solution somewhere in the forum. Just use the search!

Greetings!
#5

[eluser]Clooth[/eluser]
I have tested it.

"If I want to have other(custom) fields in the DB" - was the main question I pointed out. Smile Search didn't help.
#6

[eluser]zutis[/eluser]
Do you want there "custom" fields to store data forever or just the length of the session.

If forever then you should make a separate table a just store a reference in the session e.g. user_id to that record in the other table.

If you are looking to store custom data for the length of the session only then you should just use the $this->session->set_userdata($array) code. It does store the data in the DB still - just not in separate fields. But you don't need to even worry about that as you can store as many different values as you like. Even arrays and objects!
#7

[eluser]Clooth[/eluser]
I need to be able to search the sessions table by this custom information, so arrays or objects don't help me! Big Grin
#8

[eluser]zutis[/eluser]
In which case you definitely want to write models for the data sets you need and then just store the unique ids in the session so that you can use the ids to get the data from the model.

E.g. write a user model and once a user logs in stored the user_id in the session. From there on call the model to get the user data.




Theme © iAndrew 2016 - Forum software by © MyBB