你为什么要在PHP中使用$ _GET?

use*_*419 3 php post get http request

我还没有正式开始学习PHP,只是浏览几个教程,我有一个问题.为什么有人会选择使用Get vs Post?为什么你想要url栏中显示的数据?我知道post用于密码和重要信息,但我不明白为什么你会使用get而不是只是一直发布?

Thanks for any insight.

Mic*_*son 28

$_GET is useful for pages where users are requesting data - such as a search page, and pages that a user might want to bookmark and share with others. Actions that should be readonly.

$_POST is useful for pages where users are "posting" data - such as a signup form. $_POST should be used when you don't want your visitors to be able to bookmark page. Actions that write data.

As prodigitalson added: you may use $_POST or $_GET for any operation, but it is good practice to use them as described above.

  • "+ 1"获得了很好的答案. (3认同)
  • 我想补充说,将"GET"视为只读操作也是有用的,其中`POST`是读/写.这不是'GET` /`POST`固有的限制,而是一个很好的做法. (3认同)

Nei*_*kar 17

If you want people to be able to share the link with their friends...for eg http://example.com/products.php?product_id=12


Sin*_*nür 9

GET请求是幂等的.POST请求更改服务器状态.

这是一个HTTP问题,而不是PHP问题.