note 87462 added to function.session-start

From: Date: Sat, 06 Dec 2008 04:31:25 +0000
Subject: note 87462 added to function.session-start
Groups: php.notes 
Request: Send a blank email to php-notes+get-147732@lists.php.net to get a copy of this message
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" ); ?> ---- Server IP: 69.147.83.197 Probable Submitter: 115.147.3.121 ---- Manual Page -- http://www.php.net/manual/en/function.session-start.php Edit -- https://master.php.net/note/edit/87462 Del: integrated -- https://master.php.net/note/delete/87462/integrated Del: useless -- https://master.php.net/note/delete/87462/useless Del: bad code -- https://master.php.net/note/delete/87462/bad+code Del: spam -- https://master.php.net/note/delete/87462/spam Del: non-english -- https://master.php.net/note/delete/87462/non-english Del: in docs -- https://master.php.net/note/delete/87462/in+docs Del: other reasons-- https://master.php.net/note/delete/87462 Reject -- https://master.php.net/note/reject/87462 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#147732) next »