PHP Classes
Icontem

File: usage_example.php


  Search   All class groups All class groups   Latest entries Latest entries   Top 10 charts Top 10 charts   Newsletter Newsletter   Blog Blog   Forums Forums   Help FAQ Help FAQ  
  Login   Register  
Recommend this page to a friend! ReTweet ReTweet Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of João Romão  >  MySessions  >  usage_example.php  
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
 

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(1999);
$_SESSION['another'] = rand(99999999);
 
echo 
'<pre>'$session->debug(), '</pre >';
?>

 
  Advertise on this site Advertise on this site   Site map Site map   Statistics Statistics   Site tips Site tips   Privacy policy Privacy policy   Contact Contact  

For more information send a message to :
info at phpclasses dot org.
Copyright (c) Icontem 1999-2009 PHP Classes - PHP Class Scripts
  PHP Book Reviews - Reviews of books and other products