b2evolution

Multilingual multiuser multiblog engine

b2evolution Technical Documentation (CVS HEAD) [ class tree: evocore ] [ index: evocore ] [ all elements ]

Class: Session

Source Location: /blogs/inc/sessions/model/_session.class.php

Class Session

Class Overview

A session tracks a given user (not necessarily logged in) while he's navigating the site.

A session also stores data for the length of the session.

Sessions are tracked with a cookie containing the session ID. The cookie also contains a random key to prevent sessions hacking.

Located in /blogs/inc/sessions/model/_session.class.php [line 57]



		
		
		
		

Properties

Methods

[ Top ]
Property Summary
integer   $ID   The ID of the session.
boolean   $is_validated   Is the session validated? This means that it was created from a received cookie.
string   $key   The session key (to be used in URLs).
integer   $user_ID   The user ID for the user of the session (NULL for anonymous (not logged in) user).
array   $_data   Data stored for the session.
mixed   $_session_needs_save  

[ Top ]
Method Summary
Session   Session()   Constructor
void   assert_received_crumb()   Assert that we received a valid crumb for the object we want to act on.
string   create_crumb()   Create a crumb that will be saved into the Session and returned to the caller for inclusion in Form or action url.
void   dbsave()   Updates session data in database.
void   delete()   Delete a value from the session data.
mixed   get()   Get a data value for the session. This checks for the data to be expired and unsets it then.
false|User   &get_User()   Get the attached User.
boolean   has_User()   Check if session has a user attached.
void   logout()   Logout the user, by invalidating the session key and unsetting $user_ID.
void   reload_data()   Reload session data.
void   session_needs_save()  
void   set()   Set a data value for the session.
void   set_User()   Attach a User object to the session.
void   set_user_ID()   Attach a user ID to the session.

[ Top ]
Properties
integer   $ID [line 63]

The ID of the session.


[ Top ]
boolean   $is_validated = false [line 83]

Is the session validated? This means that it was created from a received cookie.


[ Top ]
string   $key [line 69]

The session key (to be used in URLs).


[ Top ]
integer   $user_ID [line 76]

The user ID for the user of the session (NULL for anonymous (not logged in) user).


[ Top ]
array   $_data [line 93]

Data stored for the session.

This holds an array( expire, value ) for each data item key.

API Tags:
Access:  protected


[ Top ]
mixed   $_session_needs_save = false [line 95]

[ Top ]
Methods
Constructor Session  [line 104]

  Session Session( )

Constructor

If valid session cookie received: pull session from DB Otherwise, INSERT a session into DB



[ Top ]
assert_received_crumb  [line 549]

  void assert_received_crumb( string $crumb_name  )

Assert that we received a valid crumb for the object we want to act on.

This will DIE if we have not received a valid crumb.

The received crumb must match a crumb we previously saved less than 2 hours ago.

Parameters:
string   $crumb_name:  crumb name


[ Top ]
create_crumb  [line 511]

  string create_crumb( string $crumb_name  )

Create a crumb that will be saved into the Session and returned to the caller for inclusion in Form or action url.

For any action, a new crumb is generated every hour and the previous one is saved. (2 hours are valid)

Parameters:
string   $crumb_name:  crumb name

API Tags:
Return:  crumb value


[ Top ]
dbsave  [line 434]

  void dbsave( )

Updates session data in database.

NOTE: Debuglog additions will may not be displayed since the debuglog may alreayd have been displayed (shutdown function)



[ Top ]
delete  [line 414]

  void delete( string $param  )

Delete a value from the session data.

Parameters:
string   $param:  Name of the data's key.


[ Top ]
get  [line 354]

  mixed get( string $param, [mixed $default = NULL]  )

Get a data value for the session. This checks for the data to be expired and unsets it then.

Parameters:
string   $param:  Name of the data's key.
mixed   $default:  Default value to use if key is not set or has expired. (since 1.10.0)

API Tags:
Return:  The value, if set; otherwise $default


[ Top ]
get_User  [line 334]

  false|User &get_User( )

Get the attached User.



[ Top ]
has_User  [line 323]

  boolean has_User( )

Check if session has a user attached.



[ Top ]
logout  [line 301]

  void logout( )

Logout the user, by invalidating the session key and unsetting $user_ID.

We want to keep the user in the session log, but we're unsetting $user_ID, which refers to the current session.

Because the session key is invalid/broken, on the next request a new session will be started.

NOTE: we MIGHT want to link subsequent sessions together if we want to keep track...



[ Top ]
reload_data  [line 476]

  void reload_data( )

Reload session data.

This is needed if the running process waits for a child process to write data into the Session, e.g. the captcha plugin in test mode waiting for the Debuglog output from the process that created the image (included through an IMG tag).



[ Top ]
session_needs_save  [line 241]

  void session_needs_save( $session_needs_save  )

Parameters:
   $session_needs_save: 


[ Top ]
set  [line 386]

  void set( string $param, mixed $value, [integer $expire = 0]  )

Set a data value for the session.

Updated values get saved to the DB automatically on shutdown, in shutdown().

Parameters:
string   $param:  Name of the data's key.
mixed   $value:  The value
integer   $expire:  Time in seconds for data to expire (0 to disable).


[ Top ]
set_User  [line 252]

  void set_User( User $User  )

Attach a User object to the session.

Parameters:
User   $User:  The user to attach


[ Top ]
set_user_ID  [line 265]

  void set_user_ID( integer $user_ID  )

Attach a user ID to the session.

NOTE: ID gets saved to DB on shutdown. This may be a "problem" when querying T_sessions for sess_user_ID.

Parameters:
integer   $user_ID:  The ID of the user to attach


[ Top ]

Documentation generated on Sat, 06 Mar 2010 04:22:51 +0100 by phpDocumentor 1.4.2. This site is hosted and maintained by Daniel HAHLER (Contact).