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

发布于 2024-09-14 07:02:15 字数 145 浏览 1 评论 0原文

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

感谢您的任何见解。

I haven't officially started learning PHP, just skimming through a couple tutorials and I have a question. Why would some one choose to use Get vs Post? Why would you ever want the data shown in the url bar? I understand post is used for passwords and important info but I don't understand why you would use get instead of just post all the time?

Thanks for any insight.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

暖阳 2024-09-21 07:02:16

您是否计划在每个链接上填写表格和按钮来填充您的网站?您在此站点中看到的每个链接都在发送 GET 变量..也许您的问题与表单中的“方法”属性有关,如果是这种情况,那么 90% 的案例帖子是更好的选择
不用担心安全性:)仅仅因为您没有在导航栏中看到信息并不意味着它是安全的,只需点击两次即可观看通过邮寄发送的信息;)

are you planning to fill your website with forms and buttons on each link?? every link you see in this site is sending GET variables.. maybe your question is related to the "method" attribute in a form, if that's the case, well 90% of the cases post is a better choice
dont worry about the security :) just because you dont see the information in the navigation bar doesnt mean that its secured, watching the information sent by post is only two clicks away ;)

陌上青苔 2024-09-21 07:02:16

有时,您必须将参数(数据)传递给脚本而不提交表单,或者想要将该脚本共享给某人。在这种情况下 $_GET 很有用。

GET 方法可能会导致 URL 过长,甚至可能超出某些浏览器和服务器对 URL 长度的限制。

Some times you have to pass params(data) to a script without form submit OR want to share that script to someone. In that case $_GET is useful.

GET method may result in long URLs, and may even exceed some browser and server limits on URL length.

若有似无的小暗淡 2024-09-21 07:02:16

GET 的用途有多种。
如果您想与朋友分享 URL,例如 http://site.com/share.php ?id=123 <- 经常使用。

它经常用来做动态动作。

当不应共享敏感信息时,通常会使用 POST。

你可以在谷歌上查找以了解更多=)

GET can be used for multiply reasons..
If you want to share a URL with your friend, like http://site.com/share.php?id=123 <- Often used.

Its often used to do dynamic actions.

POST is often used when sensetive information should not be shared.

You can look it up on google to learn more =)

云裳 2024-09-21 07:02:15

$_GET 对于用户请求数据的页面非常有用,例如搜索页面以及用户可能想要添加书签并与其他人共享的页面。应该是只读的操作。

$_POST 对于用户“发布”数据的页面(例如注册表单)非常有用。当您希望访问者能够为页面添加书签时,应使用$_POST写入数据的操作。

prodigitalson 补充道:您可以使用 $_POST$_GET适用于任何操作,但最好按照上述方式使用它们。

$_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.

时光磨忆 2024-09-21 07:02:15

如果您希望人们能够与他们的朋友分享链接...例如 http:// example.com/products.php?product_id=12

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

往日情怀 2024-09-21 07:02:15

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

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

GET requests are idempotent. POST requests change server state.

This is an HTTP question, not a PHP question.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文