note 87462 deleted from function.session-start by peehaa

From: Date: Fri, 09 Dec 2016 22:13:11 +0000
Subject: note 87462 deleted from function.session-start by peehaa
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-208339@lists.php.net to get a copy of this message
Note Submitter: zidaine_38 at yahoo dot com ---- <?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" ); ?>

« previous php.notes (#208339) next »