11th chapter Form and Validation _php tutorial

Source: Internet
Author: User
Learning Essentials:
1.Header () function
2. Receiving and validating data

The reason we are interested in the Web is that it is primarily published and collected through HTML-based forms.
The ability to interest. These forms are used to encourage feedback from the site, to conduct forum sessions, to collect e-mail addresses for online orders, and so on.
However, encoding an HTML form is only part of the necessary action to effectively accept user input, which must be done by the server-side
Component to handle the input.

A Header () function

Header is the string that the server sends to the browser before the HTTP protocol passes the HTML data
There is a blank line separating the header from the HTML file.
1. Used to re-orient the specified URL

 
  < span="">(' location:http://www.baidu.com '< span="">?>

2. For setting page character encoding

 
  < span="">(' content-type:text/html; CHARSET=GBK '  < span="">    < span="">  Hey, I'm Chinese! The page encoding is GBK, and the file< span="">is GBK '?>

Note: Unless output buffering is enabled, these commands must be executed before any output is returned.
Enable output buffering: Ob_start ()

 
  < span="">< span="">?>

Two Accepting and validating data

GET vs. Post
When you process a form, you must specify how the information entered into the form is transferred to its destination (method= "").
For this, WEB developers can take get and post. When you use the Get method to send data, all fields are appended
To the URL of the browser, and sends the data with the URL address. When the Post method is used, the value is used as the standard
Value is sent.
PHP uses $_get and $_post super global variables to handle GET and POST variables, respectively. By using this
Two hyper-global variables that specify exactly where the information should come from and process the data the way you want.
Use $_get or $_post to receive data
1.$_get[' username '), the form method to be sent must be GET;
2.$_post[' username '), the form method to be sent must be POST;
3. Use Isset () to verify that the $_get[' username '] Super global variable is defined;
4. Use the Htmlspecialchars () function to filter the HTML special characters.
Validation of data validation
1. Use the function trim () to remove the front and back space of the data;
2. Use the function strlen () to determine the length of the data;
3. Use function Is_numeric () to determine that the data is a pure number;
4. Use regular expressions to verify that the mailbox is legitimate.

 
  < span="">(!  < span="">  < span="">  ([< span="">'send ']!= 'submit ' < span=""> < span=""> ('  < span="">  < span=""> Location:Demo1.php '  < span="">  < span=""> ((' < span="">/[\w\.] {2,255}) @ ([\w\-]{1,255}). ([a-z]{2,4})/',< span="">[' email '  < span="">    < span="">  e-mail legal  ' < span=""> < span="">' email is not legal '?  < span="">  < span="">  < span=""> >

Note: The article is from Eon to PHP video tutorial, this article is limited to exchange use, not for commercial purposes, otherwise the consequences.

http://www.bkjia.com/PHPjc/759628.html www.bkjia.com true http://www.bkjia.com/PHPjc/759628.html techarticle Learning points: 1.Header () function 2. Receive and validate data we are interested in the web and think it is useful because of its ability to publish and collect information primarily through HTML-based forms. These ...

  • Related Article

    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.