Chapter 2 Form and verification. Learning points: 1. header () function 2. we are interested in receiving and verifying data on the Web. the reason we think it is useful is that it mainly uses HTML-based form publishing and information collection capabilities. These
Learning points:
1. Header () function
2. receive and verify data
We are interested in the Web. the reason we think it is useful is that it mainly publishes and collects emails through HTML-based forms.
Information capabilities. These forms are used to encourage website feedback, conduct forum sessions, collect online order email addresses, and so on.
However, encoding HTML forms is only a part of the operations required to effectively accept user input, and must be performed by the server.
Component to process input.
I. Header () function
The header is a string sent by the server before passing HTML data to the browser over HTTP.
The header and HTML file must be separated by a blank line.
1. used to redirect the specified URL
2. used to set the page Character encoding
Note: Unless output buffering is enabled, these commands must be executed before any output is returned.
Enable output buffer: ob_start ()
II. acceptance and verification data
GET and POST
When processing a form, you must specify the way in which the information entered into the form is transmitted to its destination (method = "").
For this purpose, Web developers can use GET and POST. When data is sent using the GET method, all domains are appended.
After the URL of the browser, and the data is sent with the URL address. When the POST method is used, the value will be used as the standard
Send value.
PHP uses the $ _ GET and $ _ POST Super global variables to process GET and POST variables respectively. By using this
Two Super global variables can accurately specify where the information should come from and process the data as you want.
Use $ _ GET or $ _ POST to receive data
1. $ _ GET ['username'], the method of the sent form must be get;
2. $ _ POST ['username'], the method of the sent form must be post;
3. use isset () to verify whether the $ _ GET ['username'] Super global variable is defined;
4. use the htmlspecialchars () function to filter special HTML characters.
Verify the data validity
1. use the trim () function to remove leading and trailing spaces of data;
2. use the strlen () function to determine the data length;
3. use the is_numeric () function to determine that the data is a pure number;
4. use a regular expression to verify whether the email address is valid.
Note: This article is a video tutorial from Li Yanhui PHP. This article is intended for communication purposes only and cannot be used for commercial purposes. Otherwise, the consequences will be borne by you.
Handler 1. Header () function 2. we are interested in the Web in receiving and verifying data. the reason we think it is useful is that it mainly uses HTML-based form Publishing and receiving information capabilities. These...