example
1 <?php 2 # include the configuration file. 3 require_once($_SERVER['DOCUMENT_ROOT'] . '../global.conf.php'); 4 require_once($APP['path']['core'] . 'net/http/session/Bs_SimpleSession.class.php'); 5 6 ################################################################################ 7 # Start of the session 8 $session =& $GLOBALS['Bs_SimpleSession']; // Use the per ref operator '=&' <-- !! 9 10 ################################################################################ 11 # Sample 3 12 # -------- 13 # Chage some properties 14 $prop = array ( 15 'path' => 'c:/', 16 'maxStandbyTime' => 0.2, // <- How long should the session stay valid (in min) if not used. 0 means until browser end. 17 'maxLifeTime' => 0.5 // <- Independent of use, invalidat after this time (im min). 0 means until browser end. 18 ); 19 $ok = $session->setProperty($prop, 'shortTimeSession'); // <----- Optional. Set property here if needed 20 if (!$ok) XR_dump($session->getErrors(), __LINE__, '', __FILE__); 21 22 $output = ''; 23 $output .= "Setting Session Property to "; 24 $output .= "maxLifetime: {$prop['maxLifeTime']}min, maxStandbyTime: {$prop['maxStandbyTime']}min\n"; 25 $output .= "<hr>"; 26 $aVariable=0; 27 28 if (!$session->isRegistered('my_var', 'shortTimeSession')) { 29 $output .= "<span style='color: Red; font-weight: bold;'>- SESSION TIMED OUT ! - </span><br>\n"; 30 } else { 31 $output .= "<span style='color: Green; font-weight: bold;'> SESSION Running !</span><br>\n"; 32 } 33 $ok = $session->register('my_var', $aVariable, 'shortTimeSession'); 34 if (!$ok) XR_dump($session->getErrors(), __LINE__, '', __FILE__); 35 $output .= "Simple Counter: <B>" . $aVariable++ . "</B><br>"; 36 37 ?> 38 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> 39 40 <html> 41 <head> 42 <title>Example 3 of Bs_SimpleSession</title> 43 </head> 44 45 <body> 46 <H2>Bs_SimpleSession Sample 3</H2> 47 48 <hr> 49 <?php 50 echo $output; 51 ?> 52 <br><br> 53 54 <a href="#" onClick="javascript:var block=document.getElementById('sessProps'); block.style.visibility='hidden'">Hide Session Properties</a> 55 <div id="sessProps" style="visibility : visible;"> 56 <a name="x" href="x"></a> 57 <?php 58 echo $session->toHtml('shortTimeSession'); 59 ?> 60 </div> 61 </body> 62 </html>
|