note 87462 modified in function.session-start by danbrown
| From: | danbrown@php.net | Date: | Sat, 06 Dec 2008 04:42:26 +0000 |
| Subject: | note 87462 modified in function.session-start by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-147733@lists.php.net to get a copy of this message | ||
<?php
class SESSION
{
public function __construct ()
{
self :: commence ();
}
public function commence ()
{
if ( !isset( $_SESSION ['ready'] ) )
{
session_start ();
$_SESSION ['ready'] = TRUE;
}
}
public function set ( $fld , $val )
{
self :: commence ();
$_SESSION [ $fld] = $val;
}
public function un_set ( $fld )
{
self :: commence ();
unset( $_SESSION [$fld] );
}
public function destroy ()
{
self :: commence ();
unset ( $_SESSION );
session_destroy ();
}
public function get ( $fld )
{
self :: commence ();
return $_SESSION [$fld];
}
public function is_set ( $fld ) {
self :: commence ();
return isset( $_SESSION [$fld] );
}
}
?>
This Class is handy to all who want easy session handling.
Just include () or require () this to pages where you will have to use session.
example:
<?php
include ( "/path/to/sess.inc.php" );
if( !SESSION :: is_set ( "number" ) )
{
SESSION :: set ( "number" , 1 );
}
else
{
$_SESSION ["number"] ++;
}
echo SESSION :: get ( "number" );
?>
--was--
class SESSION
{
public function __construct ()
{
self :: commence ();
}
public function commence ()
{
if ( !isset( $_SESSION ['ready'] ) )
{
session_start ();
$_SESSION ['ready'] = TRUE;
}
}
public function set ( $fld , $val )
{
self :: commence ();
$_SESSION [ $fld] = $val;
}
public function un_set ( $fld )
{
self :: commence ();
unset( $_SESSION [$fld] );
}
public function destroy ()
{
self :: commence ();
unset ( $_SESSION );
session_destroy ();
}
public function get ( $fld )
{
self :: commence ();
return $_SESSION [$fld];
}
public function is_set ( $fld ) {
self :: commence ();
return isset( $_SESSION [$fld] );
}
}
This Class is handy to all who want easy session handling.
Just include () or require () this to pages where you will have to use session.
example:
<?php
include ( "/path/to/sess.inc.php" );
if( !SESSION :: is_set ( "number" ) )
{
SESSION :: set ( "number" , 1 );
}
else
{
$_SESSION ["number"] ++;
}
echo SESSION :: get ( "number" );
?>
http://php.net/manual/en/function.session-start.php