Key point: when the "$ _ GET" variable is applied, all the variable names and variable values are displayed in the URL address bar. therefore, this method cannot be applied when the information you send contains a password or other sensitive information. Because all the information will be displayed in the URL address bar, we can put it as a tag in the folder. This is useful in many cases.
The PHP $ _ GET and $ _ POST variables are used to obtain information in the form, such as the user input information.
PHP form control
When processing HTML and PHP forms, we need to remember that any form element in the HTML page can be actively used for PHP scripts:
Form example:
The preceding HTML page contains two input boxes [input field] and a [submit] button. When you fill in the information and click the submit button, the data in the form will be sent to the "welcome. php" file.
The "welcome. php" file is as follows:
Welcome .
You are Years old.
The above script will output the following results:
Welcome John.
You are 28 years old.
PHP $ _ GET and $ _ POST variables will be explained in the next chapter.
Form validity verification [Form Validation]
The user input information should be verified through the client script program (such as JavaScript) browser as much as possible; the information validity verification through the browser can improve the efficiency and reduce the download pressure on the server.
If the user input information needs to be stored in the database, you must consider verifying the validity on the server side. The best way to verify the information validity on the server is to send the form information to the current page for verification, rather than transfer it to other pages for verification. If an error occurs in the form, you can obtain the error information directly on the current page. This makes it easier for us to invent error messages.
The PHP $ _ GET variable obtains the "value" from the form through the get method.
$ _ GET variable
The $ _ GET variable is an array containing the name [name] and value [value] (these names and values are sent through the http get method and can all be used ).
The $ _ GET variable applies "method = get" to obtain the form information. The information sent through the GET method is visible (it will be displayed in the address bar of the browser) and has a length limit (the total length of the information cannot exceed 100 characters [character]).
Case
After you click "Submit", the URL method is displayed.
"Welcome. the php file can apply the "$ _ GET" variable to obtain form data (note: the name in the form field [form field] will take the initiative as the key word of ID in the "$ _ GET" Array ):
Welcome .
You are Years old!
Why apply "$ _ GET "?
Key point: when the "$ _ GET" variable is applied, all the variable names and variable values are displayed in the URL address bar. therefore, this method cannot be applied when the information you send contains a password or other sensitive information. Because all the information will be displayed in the URL address bar, we can put it as a tag in the folder. This is useful in many cases.
Note: If the variable value to be sent is too large, the http get method is not practical. The number of sent messages cannot exceed 100 characters.
$ _ REQUEST variable
The PHP $ _ REQUEST variable contains $ _ GET, $ _ POST, and $ _ COOKIE content.
The PHP $ _ REQUEST variable can be used to obtain the form data sent through the "GET" and "POST" methods.
Case
Welcome .
You are Years old!
The function of the PHP $ _ POST variable is to get the form variable sent by the method = "post" method.
$ _ POST variable
The $ _ POST variable is an array containing the name [name] and the value [value] (these names and values are sent through the http post method and can all be used)
The $ _ POST variable applies "method = POST" to obtain the form information. The information sent through the POST method is invisible and there is no limit on the length of the information.
Case
After you click "Submit", the URL does not contain any form data.
"Welcome. the "$ _ POST" variable can be applied to the php file to obtain form data (note: the name in the form field [form field] will take the initiative as the ID keyword in the "$ _ POST" Array ):
Welcome .
You are Years old!
Why apply $ _ POST?
Variables sent through http post are not displayed in the URL.
There is no limit on the variable size.
However, because the variables cannot be displayed in the URL, it is impossible to store the page as a tag in the folder.
$ _ REQUEST variable
The PHP $ _ REQUEST variable contains $ _ GET, $ _ POST, and $ _ COOKIE content.
The PHP $ _ REQUEST variable can be used to obtain the form data sent through the "GET" and "POST" methods.
Case
Welcome .
You are Years old!