note 120292 deleted from function.session-start by peehaa
| From: | peehaa@php.net | Date: | Fri, 09 Dec 2016 21:41:34 +0000 |
| Subject: | note 120292 deleted from function.session-start by peehaa | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-208302@lists.php.net to get a copy of this message | ||
Note Submitter: bobo
----
How to use Sessions (Simple Example)
/File 1 (example1.php)
<?php
session_start();
$sID=session_id();
echo "<p>Session ID:".$sID."<br>"; //Shows the Session ID
?>
<html>
<body>
<form>
<p>
<label for"Name">Name</label>
<input type="text" name="Name" id="nn">
</p>
<p>
<label for"Secondname">Secondname</label>
<input type="text" name="Secondname" id="vn">
</p>
<p>
<input type="submit" name="submit" value="ok">
</p>
<?php
if(isset($_GET["submit"]))
{
$Name=$_GET["Name"];
$Secondname=$_GET["Secondname"];
$_SESSION["Name"]=$Name; //Save Name in Array $_SESSION
$_SESSION["Secondname"]=$Secondname; //Save Secondname in Array $_SESSION
echo "<p>Hi ".$Name." ".$Secondname."</p>";
echo "<p><a href='example2.php'>Next File.......</p>";
}
?>
/File 2 (example2.php)
<?php
session_start();
$sID=session_id();
echo "<p>Session ID:".$sID."<br>";
?>
<?php
$Name=$_SESSION["Name"];
$Secondname=$_SESSION["Secondname"];
echo"Your are Logged on as:".$Name ." ".$Secondname;
echo "<p><a href='example3.php'>Link.......</p>";
?>
/File 3 (example3.php)
<?php
session_start();
$sID=session_id();
echo "<p>Session ID:".$sID."<br>";
$Name=$_SESSION["Name"];
$Secondname=$_SESSION["Secondname"];
session_destroy();
?>