CodeIgniter Forums
A question regarding the Session Class - 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: A question regarding the Session Class (/showthread.php?tid=9309)



A question regarding the Session Class - El Forum - 06-20-2008

[eluser]EEssam[/eluser]
Hello,

I do not understand what is so good in having the following information available:

[array]
(
'session_id' => random hash,
'ip_address' => 'string - user IP address',
'user_agent' => 'string - user agent data',
'last_activity' => timestamp
)

How can this help me in creating a member area, for example?

Please clarify. Thanks.


A question regarding the Session Class - El Forum - 06-20-2008

[eluser]Matthieu Fauveau[/eluser]
These values are actually used by the session class itself to keep track of the users, nothing else...


A question regarding the Session Class - El Forum - 06-21-2008

[eluser]Crimp[/eluser]
You can put any information you want in the session (up to its limit). The above data is included in the session class by default.

To create a member area, with restricted access, you can for exmaple set session data called "logged_in" to TRUE.

Your session userdata array wil then be:

Code:
[array]
(
‘session_id’ => random hash,
‘ip_address’ => ‘string - user IP address’,
‘user_agent’ => ‘string - user agent data’,
‘last_activity’ => timestamp,
'logged_in' => TRUE
)

In your member area methods you can then check for:

Code:
if ($this->session->userdata('logged_in'))
{
// do if logged in
}