Home Tutorial Php Examples Create session variable.

 
 

Create session variable.
Posted on: July 30, 2009 at 12:00 AM
Advertisement
In this example you will learn how to create session variable in PHP.

Create session variable

In this example, you will learn how to create session variable in HTML form. You can use your email id to find the session value.

First you will have to create a form in HTML in which you will have to create an Email field and fix submit buttton.

Create a session variable code in PHP and call the value of this variable in the HTML form using post action command of PHP.

Email has been set to find the session value, if the program finds the correct email address, the value of the session is set. 

<?php
session_start (); #session start
if($_POST["submit"]){
$email=$_POST["email"];
session_register ("email"); #session Register
$_SESSION["email"]=$email; #session Veriable
$sessionvalue= $_SESSION["email"]; #Find Session variable value
echo "Your Email ID is ".$sessionvalue;
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head><title>Session Register</title></head>
<body>
<form name="session" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>" >
<table width="80%" border="0" cellspacing="0" cellpadding="0" style="color:#333333;"> 

<tr> 
<td width="20%" height="27" style="padding-left:10px;">Email</td> 
<td width="32%">: <input type="text" name="email" class="inputbox" /></td> 
<td width="48%" align="left"></td>
</tr> 
<tr><td><input name="submit" type="submit" value="Submit" onClick="return validate(this);"/></td></tr> 
<tr> 
</table> 
</form> 
</body>
</html>

Advertisement

Related Tags for Create session variable.:


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: July 30, 2009

Recommend the tutorial

Advertisements Advertisements
 

 

 

DMCA.com