Académique Documents
Professionnel Documents
Culture Documents
e-mail:(ssp@ucsc.cmb.ac.lk)
Advanced Digital Media Technology Center-University of Colombo School of Computing
What is a session ?
A session is a series of related interactions between a single client & a web server, taking place over an extended period of time. It is a method of making Data persist, even when you exit one page & go to another.
Session Variables
How do we make the Browser remember a certain unit of data while we navigate from page to page? Simply, assign that data to a session variable, using the following format - $_SESSION[ << some unique name >> ]. eg. :$_SESSION[stu_name] = Mr. ABC, $_SESSION[stu_id] = 8880123 Here, stu_name and stu_id uniquely identify a variable. Another method is, to use the predefined function session_register( )
Stopping Sessions
Often times, you will need to destroy a session completely. This is a simple two step process: session_unset(); session_destroy();
Sample Codes
<?php // You don't need session_start() // in the first HTML form page. ?> <html> <body> <form method=post action=page2.php> <input type=text name=Info> <input type=submit> </form> </body> </html> <?php session_start(); $_SESSION["data"]=$_POST["Info"]; ?> <?php session_start(); ?>