什么是“?"用于在 php 中的 URL 中的符号? [英] What is the "?" symbol in URL used for in php?

查看:29
本文介绍了什么是“?"用于在 php 中的 URL 中的符号?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 PHP 新手.在学习PHP语言的过程中,我注意到,有的网站会有这样的网址:

I am new to PHP. In the path of learning PHP language, I notice that, some website would this kind of URL:

www.website.com/profile.php?user=roa3&...

www.website.com/profile.php?user=roa3&...

我的问题:

  1. 什么是?"符号用于?

  1. What is the "?" symbol used for?

如果我正在开发一个 php 网站,我必须在我的 URL 中使用它吗?例如,用户(roa3)成功登录后,我将重定向到www.website.com/profile.php?user=roa3"而不是www.website.com/profile.php"

If I were develop a php website, must I use it in my URL? For example, after a user(roa3) successful logged in, I will redirect to "www.website.com/profile.php?user=roa3" instead of "www.website.com/profile.php"

使用它有什么优点和缺点?

What are the advantages and disadvantages of using it?

推荐答案

好问题,简而言之,

  1. ?"代表查询的开始包含数据的字符串传递给服务器.在这种情况下您将 user=roa3 传递给profile.php 页面.你可以得到数据通过使用 $_GET['user'] 内个人资料.php.查询字符串是从客户端代理向服务器发送数据的方法之一.另一个是把数据放在HTTP body中POST到服务器,浏览器直接看不到HTTP POST数据.

  1. "?" stands for the start of querying string which contains the data to be passed to the server. in this case you are passing user=roa3 to profile.php page. You can get the data by using $_GET['user'] within profile.php. querystring is one of the methods to send data to the server from client agent. The other one places the data in HTTP body and POST to the server, you don't see the HTTP POST data directly from browser.

查询字符串可由用户编辑并且对公众可见.如果www.website.com/profile.php?user=roa3旨在公开,那么它是很好,否则你可能想使用获取当前用户的会话上下文.

querystring can be edited by user and it is visible to the public. If www.website.com/profile.php?user=roa3 is intended to be public then it is fine, otherwise you may want to use session to get current user's context.

它是一种灵活的方式将数据传递给服务器,但它是可见的对用户可编辑,对于某些敏感数据,至少产生附加之前的某种散列它到查询字符串,这可以防止用户编辑或理解它的意义.然而这并不能阻止一个像样的黑客做错事网站.不同的浏览器支持不同的最大 URL 长度,冗长的 URL 由这些查询字符串参数组成.如果要发送大量数据,请将数据放在 HTTP 正文中并 POST 到服务器.

it is a flexible way to pass data to the server, but it is visible and editable to the users, for some sensitive data, at least produce some kind of hash before attaching it to the querystring, this prevents users to edit it or understanding the meaning of it. However this doesn't prevent a decent hacker to do something wrong about your website. Different browsers support different max length of URL, the lengthy URL is made up by those querystring parameters. If you want to send large amount of data, place the data in the HTTP body and POST to the server.

这篇关于什么是“?"用于在 php 中的 URL 中的符号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆