1
session
CGuild1.com > Tips & Tricks > session

Setting and Display a Session



A small piece of code for setting, displaying and destroying session in PHP

<?php
session_start();
$r=session_id();


/* SOME PIECE OF CODE TO AUTHENTICATE THE USER, MOSTLY SQL QUERY... */

/* now registering a session for an authenticated user */
$_SESSION['username']=$username;

/* now displaying the session id..... */
echo "the session id is: ".$r;
echo " and the session has been registered for: ".$_SESSION['username'];


/* now destroying the session id */

if(isset($_SESSION['username']))
{
$_SESSION=array();
unset($_SESSION);
session_destroy();
echo "session destroyed...";
}
?>


Check out the original on StackOverflow.com.
©2024 CGuild1.com