PHP Classes
elePHPant
Icontem

File: example2.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of RS  >  Jack's Session class  >  example2.php  >  Download  
File: example2.php
Role: Example script
Content type: text/plain
Description: show session catch->throw sintax
Class: Jack's Session class
Manage user access sessions stored in a database
Author: By
Last change:
Date: 8 years ago
Size: 1,458 bytes
 

Contents

Class file image Download
<?php

// require session class
require_once('session.class.php');

// require mySQL handler class
// who can be downloaded from here: http://www.phpclasses.org/browse/package/2847.html
require_once('sql.class.php');

// set database values
$_DBHOST = 'localhost';
$_DBUSER = 'root';
$_DBNAME = 'test';
$_DBPASS = '';

// we will need this sql class
$s = new sql();

// 'start' the class
$c = new session($host); // host for the cookies (default: null)

// use of session throw->catch syntax

// catch
$message = $c->catch_msg(); // catch previous throw messages

if (is_array($message))
{
    print
'<pre>';
   
print_r($message);
    print
'</pre>';
}
else
{
    print
"message: {$message}";
}


// 1st way thow text message
// @note when we use throw_msg() the script ends(exit) and use header("location $page"); to go the the $page
$c->throw_msg('some text messae', 'example2.php'); // throw this message to example3.php
$c->throw_msg('some text messae'); // throw this message to referer

// 2nd is more advansed whe save array
$c->add_msg('array element 1');
$c->add_msg('array element 2');
$c->add_msg('array element 3');
$c->add_msg('array element 4');

// check if message was added via " $c->add_msg "
if ($c->is_msg())
{
   
$c->throw_msg(0, 'example2.php'); // throw message added with " $c->add_msg " to example3.php
   
$c->throw_msg(); // throw message added with " $c->add_msg " to referer
}

?>