Monday, 2 February 2015

Remove Sessions

To remove or delete session we use two function destroy and unset first use unset to remove all sessions and then destroy  example:


 
<!DOCTYPE html>

<html>
<body>

<?php
session_start();


$_SESSION['mysession1']='php-guides1';
$_SESSION['mysession2']='php-guides2';
$_SESSION['mysession3']='php-guides3';
$_SESSION['mysession4']='php-guides4';
$_SESSION['mysession5']='php-guides5';
?>

<p style="color:red">Session Values=<?php 
//Remove Or delete Sessions
session_unset();

session_destroy();

echo "<pre style='color:red'>";
print_r($_SESSION);
echo "</pre>";



?>

</p>


</body>
</html>



//print output

Session Values=
Array
(
)

Multiple Session Values

We can set multiple session at one time and easily fetch them in php Example:


<?php
<!DOCTYPE html>

<html>
<body>

<?php
session_start();


$_SESSION['mysession1']='php-guides1';
$_SESSION['mysession2']='php-guides2';
$_SESSION['mysession3']='php-guides3';
$_SESSION['mysession4']='php-guides4';
$_SESSION['mysession5']='php-guides5';
?>

<p style="color:red">Session Values=<?php 
echo "<pre style='color:red'>";
print_r($_SESSION);
echo "</pre>";?>
</p>

</body>
</html>
?>


Output Print:




Session

Session stored values in  variables, and from this variables we can fetch data on multiple pages .
to create session we should start it first example :
<!DOCTYPE html>

<html>
<body>

<?php
//its start session
session_start();

//set variable for session
$_SESSION['mysession']='php-guides';
?>

<p style="color:red">Session Value=<?php print($_SESSION['mysession']);?></p>

</body>
</html>

Output Print: