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: 16 years ago
Size: 1,020 bytes
 

Contents

Class file image Download
<?php

/**
 * @author João Romão (iceburn.info)
 * @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');
 
require(
'./mysessions.class.php');

$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();
 */
$session->create_table();
 
/**
 * Instead of using session_start() you must use the class built in function.
 * Same goes for session_destroy(), use $session->destroy(session_id())
 */
$session->session_start();

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