Getting Started with PHP
PHP provides two ways to interact with Web pages
Submit data through a Web Form
Passing through URL parameters
Let's start with the following interaction with a Web page through a form
<form name= "" method= "Post|get" action= "url" ></form>
Forms are submitted in two types of post get, specified by Form method
Post: A handler that sends the data in the form as a block of data to the server. This method is more secure, the data is appended to the header information, the user can not be arbitrarily modified.
Get: Attaches the form's data to the back of the URL and is simple and intuitive. Default mode
Http://url?name1=value1&name2=value2&name3=value3
So, how does PHP get the data submitted by the form?
Using Post to submit via $_get and $_post array form data is received using _$post data, and submission using the GET method is done with the $_get method. For example
Index.html<form name= "Form1" method= "Post" action= "index.php" > <label for= "username" >username</ label> <input type= "text" name= "user" id= "username" > <input type= "Submit" name= "submit" value= "Submit" >&L T;/form>//index.php<?phpif ($_post["Submit"]!=null) {echo $_post["user"];} else{echo "username is null";}
Note: When submitting data using $_post or $_get data, the index string value must be the same as the value of the form name. This is the only way to get the value of the form submission correctly
==============================================================
Encode and decode the data passed by the URL
Because the pass parameter is passed using a URL, the value of the parameter is appended directly to the URL, which is not secure. So consider using a function to encode a parameter, which can be passed by using string UrlEncode (String str) without exposing it to the back of the URL
For example
<a href= "index.php?name=<?php Echo urlencode (" Wang Xiaoming ")?>" >name</a>/* was tested to find that English could not be encoded and encoded on IE, But not in the Sogou browser */
Manuscripts: Diligent Learning qkxue.net
Extended reading:
Getting Started with PHP (7) PHP interacts with web pages
Http://qkxue.net/info/26892/PHP-PHP-Web-7
Getting Started with PHP (8) PHP interacts with JavaScript
Http://qkxue.net/info/26900/PHP-PHP-JavaScript-8
Getting Started with PHP (9) Cookies and session
Http://qkxue.net/info/27702/PHP-Cookie-Session-9
Getting Started with PHP