User session manager.
More...
User session manager.
- Version
- 1.2
- Author
- DinuSV
restoreAndReturn |
( |
|
$return_value | ) |
|
|
protected |
Used to restore the table in the model after the class has finished working with it
- Parameters
-
mixed | $return_value | : the value to return after the table has been restored |
- Returns
- mixed
Sets table for users
- Parameters
-
Get value from the session
- Parameters
-
string | $key | : index from which to return the value |
- Returns
- mixed
- Exceptions
-
setvalueAt |
( |
|
$key, |
|
|
|
$value |
|
) |
| |
Set the value at the key specified
- Parameters
-
string-numeric | $key | : index to set the value to |
mixed | $value | : value to set |
generateRnd |
( |
|
$size = 22 | ) |
|
Generate a random string at the size specified
- Parameters
-
numeric | $size | : string length |
- Returns
- string
generatePass |
( |
|
$password, |
|
|
|
$salt = null |
|
) |
| |
Generate a crypted password using the blowfish algorithm
- Parameters
-
string | $password | : given string to be crypted |
string | $salt | : salt to crypt by, auto-generated if param is missing |
- Returns
- string : crypted value
checkPass |
( |
|
$hash, |
|
|
|
$password |
|
) |
| |
Compare the password with the hash ( this can be extended for using other crypting algorithms )
- Parameters
-
string | $hash | : the hash value to compare with |
string | $password | |
- Returns
- boolean : true if passwords match
newSession |
( |
|
$data = null | ) |
|
Creates a new session
- Parameters
-
array | $data | : needs to be present in order to start the new session, containing keys and values to match with current ones |
- Returns
- boolean : true, if data is valid and the session is created, false otherwise
Checks the session according to the given session keys
- Returns
- boolean : true if the session exists and is valid, false otherwise
Opens the connection and check if the table is set for the session handler
Function that needs to be defined, in our case it does nothing
- Returns
- int
Reads the session data from the database
- Parameters
-
integer | $sid | : the id of the session |
- Returns
- string : the value of the session in case it's found, or empty string otherwise
sqlSessionWrite |
( |
|
$sid, |
|
|
|
$value |
|
) |
| |
Writes the session data to the database
- Parameters
-
string | $sid | : the session id |
string | $value | : the value to write to the database |
sqlSessionDestroy |
( |
|
$sid | ) |
|
Deletes all session information having the session id $sid
- Parameters
-
sqlSessionGarbageCollect |
( |
|
$lifetime | ) |
|
Deletes all sessions that have expired
- Parameters
-
integer | $lifetime | : the lifetime of a session in seconds |
const PASSWORD_FIELD = 'password' |
string : Predefined password field
const LASTUSED_FIELD = 'last_used' |
string : Predefined last_used field
string : Table to restore in the model after the class finishes working with the model.
string : Table used for holding user data. Example : table = 'users'
array : Map table columns with predefined fields. There are 2 predefined fields, 'password' and 'last_used'. The 'password' field is used to alert the session class to encrypt data before matching it with the table field, and the 'last_used' stores the last time the user has logged in.
Example : $_table_column = array( 'password' => 'mypassword', 'last_used' => 'last_login' )
array : Map table data with the $_SESSION variables. Each key represents the name of session key to hold the data retrieved from the table, and the value represents the table column to get the data from.
Example : The following will make the password and the id of the user available in the $_SESSION variables ( $_SESSION['pwd'] = 'some password', $_SESSION['id'] = '1234' ) $_session_keys = array( 'pwd' => 'password', 'id' => 'id' )
bool : Set this to true if you want to enable sessions to be stored in a database instead of a file in the system( linux stores them in the 'tmp' directory by default ). If you set this to true, you also need to set the table in which the sessions will be stored.
string : Table to store sessions in. Before using this, you need to enable session storage in a database, by using the field ( $_use_db ) above. The table must have the following columns and respect their properties : sid : CHAR(32), PRIMARY expiration : INT NOT NULL value : TEXT NOT NULL
string : Algorithm to be used. By default, blowfish is selected with : $2a
string : Number of times the encryption algorithm is used. Default : $10