Welcome Guest, Not a member yet? Register   Sign In
Session to database ( Need some more information)
#1

[eluser]kev[/eluser]
Hi,

I've been reading that CI doesn't use Native PHP Session but cookie to store session information. According to the user guide, for more security, validation is mandatory.

According to the user Guide for the session class :

Quote:When session data is available in a database, every time a valid session is found in the user's cookie, a database query is performed to match it.

1) Does that mean CI will automatically query my database to match a valid session? OR should I perform the query in my application myself?

2) When the database query has completed the transaction to match it, what happens?

Thanks for explaining this to me.

Regards,
Kevin
#2

[eluser]WanWizard[/eluser]
1. yes. for your application it's completely transparent where the session data is stored.
2. your session is available.

Just use the class as described in the manual.
#3

[eluser]kev[/eluser]
1. yes. for your application it’s completely transparent where the session data is stored.

That means CI will manage the query for me..

How do I detect if the session is available? Using the same methods of the session class?

Sorry for the Novice question ^^ Kinda new to CI
#4

[eluser]WanWizard[/eluser]
Correct, the class works completely transparent.

As soon as you load it, it will establish a session. If none can be found (for example because the session cookie is not present, or it has expired) a new session will be created.
Either way, it is available for you to read to / write from immediately after loading.
#5

[eluser]kev[/eluser]
Sorry to bug with that, but apart from the user guide, do you happen to have any code that save session in DB and how you work with it afterwards?
#6

[eluser]WanWizard[/eluser]
how about
Code:
// load the session library
$this->load->library('session');

if ( $value = $this->session->userdata('test') == false )
{
    echo "No session is available";
    $this->session->set_userdata('test', 'test value');
}
else
{
    echo "Look Pah, a session! Is't value is ",$value;
}
#7

[eluser]kev[/eluser]
But once saving the session in a database, how does CI handle the process to double check the session? That's what look like voodoo to me! How does all that thing work?
#8

[eluser]WanWizard[/eluser]
Like any other session solution: it stores a session_id in a cookie. And at the next page request, this cookie is retrieved, and the session_id used to query the database.




Theme © iAndrew 2016 - Forum software by © MyBB