PHP Classes
elePHPant
Icontem

File: index.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Mariusz Kaczmarczyk  >  mk_db_session  >  index.php  >  Download  
File: index.php
Role: Example script
Content type: text/plain
Description: Sample file using database session
Class: mk_db_session
Store and retrieve session variables in database
Author: By
Last change: Comments only
Date: 6 years ago
Size: 1,185 bytes
 

Contents

Class file image Download
<?php

$db_dsn
= 'mysql://user:password@host/database'; // set Data Source Name for database connection
$db_options = array (
   
'debug' => 9
); // set database options

$sess_obj = new mk_db_session;
$sess_obj->db_table_prefix = 'prefix_'; // set tables prefix
$sess_obj->db_connect($db_dsn, $db_options); // connect to database with given DSN

$sess_obj->session_load(); // load saved values from database to $MK_SESSION_VAR

// display stored values
echo "<P>$MK_SESSION_VAR['test1']</P>";
echo
"<P>$MK_SESSION_VAR['test2']</P>";
echo
"<P>$MK_SESSION_VAR['test4']</P>";
echo
"<P>$MK_SESSION_VAR['test7']</P>";

// set session variables
$MK_SESSION_VAR['test1'] = 'some string value'; // string
$MK_SESSION_VAR['test2'] = 'another string value ' . 616; // string with number
$MK_SESSION_VAR['test3'] = true; // boolean: true
$MK_SESSION_VAR['test4'] = time(); // current time
$MK_SESSION_VAR['test5'] = time() + 616.000; // float: current time + 616
$MK_SESSION_VAR['test6'] = ''; // string: empty
$MK_SESSION_VAR['test7'] = $_SERVER['REMOTE_ADDR']; // string: remote address

$sess_obj->session_save(); // save values from $MK_SESSION_VAR to database

?>