PHP Learning Notes--form data acquisition, session,cookie____php

Source: Internet
Author: User
Tags setcookie

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"];


?>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.