想要使用GET和POST方法 [英] Want to use both GET and POST methods
问题描述
我知道使用GET方法的结果页面可以被标记,而使用POST的结果页面则不能。我也知道GET方法的限制。
I know result page that uses GET method can be bookmarked while the one using POST cannot be. I also know about the restrictions of the GET methods.
现在假设我想构建一个搜索引擎,默认情况下使用GET允许用户书签,但当搜索短语的长度超过限制时,切换到POST。在服务器端,我使用$ _GET或$ _POST取决于设置的是什么。
Now suppose I want to build a search engine which by default uses GET allowing users to bookmark but when the length of the search phrase exceeds the limit, switch to POST. On the server side I make use of $_GET or $_POST depending on which is set.
这可行吗?
如果不是,为什么?
如果是,请提供简要概述。
Is this doable?
If no, why?
If yes, please provide a brief outline.
谢谢
推荐答案
这是可行的,没问题。
It is doable, no problem.
有合并GET,POST和COOKIE值的 $ _ REQUEST
数组,但更好的方法是在你的脚本中手动处理GET和POST。
There is the $_REQUEST
array that merges GET, POST, and COOKIE values but the better way would be to handle GET and POST manually in your script.
让你的引擎同时检查 $ _ GET [variable]
和 $ _ POST [变量]
并使用任何设置。如果在两种方法中都设置了变量,则需要确定要优先使用哪一个。
Just have your engine check both $_GET["variable"]
and $_POST["variable"]
and use whichever is set. If a variable is set in both methods, you need to decide which one you want to give precedence.
两种方法之间唯一值得注意的区别是GET参数具有大小限制取决于浏览器和接收Web服务器(POST也有限制,但它们通常在几兆字节的范围内)。
我认为一般规则是GET字符串不应超过1024个字符。
The only notable difference between the two methods is that a GET parameter has size limitations depending on browser and receiving web server (POST has limitations too, but they are usually in the range of several megabytes). I think the general rule is that a GET string should never exceed 1024 characters.
这篇关于想要使用GET和POST方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!