My Session How-To

Creating the database : Execute the istruction written in the file mysql.sql

Strating: Include the files "my_session.class.php" and "my_session.conf.php" in your script.

...
include("my_session.class.php");
include("my_session.conf.php");
...

Create a new object:

$session = mySession::getIstance($_MYSESSION_CONF);

Doing this you start a new session or recover an old one automatically.

You can choose to overwrite the PHP default function, so you can use normal session function, or using class defined method.

Using PHP default function is easy, just set true the OVERWRITE_PHP_FUNCTION in the configuration file.

If you choose to use class built in method they are listed below.

Registering a variabile:
You have 2 way to register a variable.
The first way is to use the $session->save(NAME,VARIABLE) method that allow you to save a variable to the session giving it a name

...
$session->save("cane","foo");
...

Doing this you save into the session a variable named "cane" with the value of "foo".
(It the equivalent that: $_SESSION["cane"] = "foo" using standard php session)

The second way is to use the $session->register(VARIABLE) method that allow you to directly save your vars with the name you gived it before.

...
$myArray["foo"] = 9;
$myArray["bar"] = 10;

$session->register($myArray);
...

Doing this you save into the session a variable named "myArray" that is the $myArray.
(It the equivalent that: $_SESSION["myArray"] = $myArray using standard php session)

Retriving a variable from session:

$session->getVar(NAME);
es: $session->getVar("cane");
or
$session->VARS[NAME];
es: $session->VARS["cane"];

Deleting a session variables :

$session->delete(NAME);
es: $session->delete("SessionArray");

The Config file:
The file is splitted in section. The fist on is the database section.

$_MYSESSION_CONF['DATABASE_TYPE']  type of the db, only mysql is supported
Connection Data:
$_MYSESSION_CONF['DB_DATABASE'] database name
$_MYSESSION_CONF['DB_PASSWORD'] database password
$_MYSESSION_CONF['DB_SERVER'] database server
$_MYSESSION_CONF['DB_USERNAME'] database user
Table data
$_MYSESSION_CONF['TB_NAME'] table name that store sessions
$_MYSESSION_CONF['SID'] "sessiond id" column name
$_MYSESSION_CONF['EXP'] name of the column that store the expire date of the session
$_MYSESSION_CONF['FEXP'] name of the column that store the forced expire date of the session
$_MYSESSION_CONF['TB_NAME_VALUE'] name of the table that store session's vars
$_MYSESSION_CONF['NAME'] name of the column that store the name of the session vars
$_MYSESSION_CONF['VALUE'] name of the column that store the value of the session vars


CAUTION: If you are using the query from the mysql.sql file don't change the Table data

General Configuration
$_MYSESSION_CONF['OVERWRITE_PHP_FUNCTION'] overwrite default PHP function
$_MYSESSION_CONF['SID_LEN'] the length of the univoque string user for the session_id
$_MYSESSION_CONF['DURATION'] duration of the session (seconds)
$_MYSESSION_CONF['MAX_DURATION'] max duration of the session (seconds). When this time is over the session will be destroyed
$_MYSESSION_CONF['SESSION_VAR_NAME'] name of the variable that store the session id (Ex: PHPSESSID).
$_MYSESSION_CONF['USE_COOKIE'] if true cookie are used to store the sessiond id, otherwise it is necessary to add to every links the session id. Es : index.php?MY_SESSIONID=$_REQUEST["MY_SESSIONID"]
$_MYSESSION_CONF['CRIPT'] if true all data stored in the database will be crypted.
$_MYSESSION_CONF['CRIPT_KEY'] the encrypt key.
$_MYSESSION_CONF['ENABLE_ANTI_HIJACKING'] Use UserAgent check to prevent Hijacking. If UserAgent check fail, session will be ended.
$_MYSESSION_CONF['ANTI_HIJACKING_SALT'] The salt used to adding more security to the UserAgent check

Foud a bugs? kaiserbaldo@gmail.com

Big Love and Respect For Every One