Home > Backend Development > PHP Tutorial > A brief analysis of some special cases of get and post, a brief analysis of getpost_PHP tutorial

A brief analysis of some special cases of get and post, a brief analysis of getpost_PHP tutorial

WBOY
Release: 2016-07-13 10:22:04
Original
890 people have browsed it

A brief analysis of some special cases of get and post, a brief analysis of getpost

Recently I was doing some work related to file uploading, etc., and encountered the following problems during the process:

Submit the form to a url with parameters (such as: res.php?param=aaa) in post mode, what will be the result?

The following will test the content related to get and post from several examples. First, let’s look at the simplest one

<html>
<body>
<&#63;php
echo $_GET ['param'];
&#63;>
 <form action="get_post_test.php&#63;param=aaa" method="get">
  <input type="text" name="param" value="bbb" /> 
  <input type="submit" value="submit">
 </form>
</body>
</html>
Copy after login

Submit to the url that already has this parameter in the get method. The result is that the corresponding value is overwritten, and the obtained param is bbb.
What if the parameters in the url are different from the name in the form? See the test example below

<html>
<body>
<&#63;php
echo $_GET ['param1'];
echo "<br>";
echo $_GET ['param2'];
&#63;>
 <form action="get_post_test.php&#63;param1=aaa" method="get">
  <input type="text" name="param2" value="bbb" /> 
  <input type="submit" value="submit">
 </form>
</body>
</html>
Copy after login

The result of this is that the value of param2 is correctly obtained, but the value of param1 is not obtained, indicating that submitting in the get method removes the parameters of the original url.
Let’s take a look at the submission via post

First, let’s look at the situation when the name values ​​are the same

<html>
<body>
<&#63;php
echo "get=" . $_GET ['param'];
echo "<br>";
echo "post=" . $_POST ['param'];
&#63;>
 <form action="get_post_test.php&#63;param=aaa" method="post">
  <input type="text" name="param" value="bbb" /> <input type="submit"
   value="submit">
 </form>
</body>
</html>
Copy after login

In this case, the output result is aaa obtained by the get method, and bbb obtained by the post method, indicating that there is no influence on each other in this case. Get and post are isolated separately.
Let’s take a look at how to use the post method to obtain the parameters behind the url

<html>
<body>
<&#63;php
echo "get=" . $_GET ['param2'];
echo "<br>";
echo "post=" . $_POST ['param1'];
&#63;>
 <form action="get_post_test.php&#63;param1=aaa" method="post">
  <input type="text" name="param2" value="bbb" /> 
  <input type="submit" value="submit">
 </form>
</body>
</html>
Copy after login

In this case, all the parameters obtained are empty, so it can be said that the parameters obtained by get and post in PHP are isolated from each other.
However, when using Java to upload files today, all the data can be obtained correctly, that is, you can use request in the servlet to obtain the form data of the post or the get data after the URL. After all, the method of obtaining parameters in the servlet is the same.

The main difference between get and post submissions, tell us one usage of each

You can directly see the submitted parameters in the get address bar, and the size is limited. Different browsers have different byte limits.
Post does not limit the size. You can't see it in the address bar.

You can query it. Use get
and try to use post
for other operations.

Compared with the POST method, what are the characteristics of the GET method?

Select C
1. Difference: In Form, you can use post or get. They are all legal values ​​​​of method. However, there are at least the following differences in the use of the post and get methods: 1. The Get method passes user input through URL requests. The parameters and values ​​passed by the Get method are displayed in the URL in the form of ?name=value&name=value. The Post method takes another form. 2. Submitting data through the get method may cause security issues. For example, a landing page. When submitting data via the get method, the username and password will appear on the URL. If the login page can be cached by the browser or others can access the customer's machine. Then, others can read the customer's account number and password from the browser's history. Therefore, in some cases, the get method can cause serious security problems. 3. Obviously the limitation of the Get method is that it is inconvenient when there are many values ​​to be transferred, otherwise the URL may be too long and cause an error. I think it is safer to use post if it is not necessary

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/851349.htmlTechArticleA brief analysis of some special situations of get and post. A brief analysis of getpost. Recently, I have been doing some work related to file uploading, etc. I encountered the following problems on the way: Submitting the form to a parameter with parameters...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template