It's free and you have access to premium codes!
Welcome back! Please login to your account.
Don't worry, we'll send you a message to help you to recover your acount.
Please check your email for instructions to activate your account.
Written by 21 November 2012
Sessions are an important resource to save data on the server. This script shows their usage by a simple example. In this example a random number is made and saved to a session; based on its value, a message is shown. If it is bigger than 5000, the 'ID' session is removed and the 'lottery' session is set to 'no'; otherwise it will be kept and 'lottery' session is set to 'yes'. Finally all data is removed.
<!-- this script is provided by https://www.phpfreecode.com coded by: Kerixa Inc. -->
<!-- This Script is from www.phpfreecpde.com, Coded by: Kerixa Inc-->
<?php
session_start();
$a= rand(1000, 9999);
echo "Your random ID is $a.<br>";
$_SESSION['ID']= $a;
if ($a>=5000) {
session_unset('ID');
echo 'Sorry Bad Chance.';
$_SESSION['lottery']= 'no';}
else{
$b= $_SESSION['ID'];
echo "Good Chance and you will be added to the Lottery with $b ID.";
$_SESSION['lottery']= 'yes';}
session_destroy();
?>
<br><font face="Tahoma"><a target="_blank" href="http://www.phpfreecode.com/"><span style="font-size: 8pt; text-decoration: none">PHP Free Code</span></a></font>
<a target='_blank' href='https://www.phpfreecode.com' style='font-size: 8pt; text-decoration: none'>Php Best Codes</a>
Comments
Here you can leave us commments. Let us know what you think about this code tutorial!