PHP Classes

File: usage_example.php

Recommend this page to a friend!
  Classes of João Romão  >  MySessions  >  usage_example.php  >  Download  
File: usage_example.php
Role: Example script
Content type: text/plain
Description: Usage example
Class: MySessions
Handler that stores session data in a MySQL table
Author: By
Last change: Comments update
Date: 8 years ago
Size: 1,020 bytes


Class file image Download

 * @author João Romão (
 * @copyright 2008

// Don't forget to include your database connection
$db_link = @mysql_connect('localhost', 'db_username', 'db_password') or die('Could not connect: ' . mysql_error());
mysql_select_db('db_name') or die('Could not select database');

$session = new MySessions();
 * Always safe to use, but not necessary is the create_table() call.
 * You can use it to create the MySQL table. It must be called before
 * $session->session_start();
 * Instead of using session_start() you must use the class built in function.
 * Same goes for session_destroy(), use $session->destroy(session_id())

 * Debugging
 * Comment and uncomment $_SESSIONS to see stored data
$_SESSION['random'] = rand(1, 999);
$_SESSION['another'] = rand(999, 99999);
'<pre>', $session->debug(), '</pre >';