The demo code is as follows:
A. Form page
<! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 frameset//en" >
<meta http-equiv= "Content-type" content= "text/html; CHARSET=GBK ">
<title>insert title here</title>
<body>
<form action= "demo12.php" method= "POST" >
Name:<input type= "text" name= "username"/></br>
Age:<input type= "text" name= "age"/></br>
Email:<input type= "text" name= "email"/></br>
Password:<input type= "Password" name= "pwd"/></br>
<input type= "Submit" name= "send" value= "submitted"/>
</form>
</body>
Two data processing pages
<?php
Header ("content-type:text/html; CHARSET=GBK ");
$username =$_post[' username '];
if (!isset ($_post["send") | | | $_post["send"]!= ' commit ') {
Header ("Location:Demo13.php");
Exit
}else{
$username =$_post[' username '];
$password =$_post["pwd"];
$password =$_cookie[' password '];
$email =$_post["email"];
$age =$_post["age"];
if (strlen ($password) <5) {
echo "<script>alert (' password length cannot be less than 5 '); History.back () </script>";
Exit
}else{
Setcookie ("username", $username, Time () +7*224*60*60);
Setcookie ("Password", $password, Time () +7*224*60*60);
Session_Start ();
$_session[' password ']= $password;
Header ("Location:Demo14.php");
}
}
?>
Third, the processing succeeds, jumps obtains the data from the cookie,session, unfolds
<?php
Header ("content-type:text/html; CHARSET=GBK ");
Session_Start ();
echo "The user name obtained in the heavy COOKIE:". $_cookie["username"];
echo "Password obtained from session:". $_session["Password"];
echo "The password obtained from the COOKIE:". $_cookie["Password"];
?>