First, create one PHP page paste this code in this file
<div class="jumbotron bg-white text-center text-white"> <div class="container bg-danger" > <form action="SessionDemo.php" method="post"> <br> <hr class="bg-light"> <h2 > Enter Session Value </h2> <hr class="bg-light"> <div class="form-group"> <input type="text" name="name" class="form-control" placeholder="Enter Session Value..." > </div> <input type="submit" value="Save Session" name="Save" class="btn btn-success btn-block"/> <input type="submit" value="Show Session" name="show" class="btn btn-warning btn-block"/> <input type="submit" value="Destroyed Session" name="del" class="btn btn-light btn-block"/> <br><br> </form> </div> </div>
Design 1
1) Start a PHP Session
A session is started with the session_start() function.
Session variables are set with the PHP global variable: $_SESSION.
$_SESSION["Session Name"] = "Value";
in this tutorial ,I set session like this
if (isset($_POST['Save'])) { if (!empty($_POST['name'])) { $a = $_POST['name']; // Set session variables $_SESSION["demo"] = $a; echo "<h3 class='alert alert-success alert-dismissable fade show text-center'>Session variables are set.</h3><br><br>"; } else { //if session is not set ... echo "<h3 class='alert alert-danger alert-dismissable fade show text-center'>Session variables are Not set.</h3><br><br>"; } }
If User Click One Save Button So that time Session is created and set the values of the session.....
Design 2
2.1
2.2
2) Get PHP Session Variable Values
Also notice that all session variable values are stored in the global $_SESSION variable:
if (isset($_POST['show'])) { // Show session variables echo "<h3 class='alert alert-success alert-dismissable fade show text-center'>Your
Session variables = " . $_SESSION["demo"] . "</h3><br><br>"; }
Design 3
3) Destroy a PHP Session:
To remove all global session variables and destroy the session, use session_unset() and session_destroy():
To remove all global session variables and destroy the session, use session_unset() and session_destroy():
if (isset($_POST['del'])) { // destroy the session session_destroy(); echo "<h3 class='alert alert-success alert-dismissable fade show text-center'>All
session variables are now removed, and the session is destroyed.</h3><br><br>"; }
Design 4
Download Source File With Designing...
No comments:
Post a Comment