检查是否在PHP中发回了请求 [英] Checking if request is post back in PHP
本文介绍了检查是否在PHP中发回了请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我如何检查请求是否是PHP回发,下面可以吗?
How can I check if the request is a post back in PHP, is the below ok?
if (isset($_POST["submit"]))
其中submit
是<input type="submit" />
推荐答案
如果您知道并期望在同一页面上有这样的提交按钮,那么该方法将起作用.
That will work if you know and expect such a submit button on the same page.
如果您对请求变量一无所知,另一种方法是检查请求方法:
If you don't immediately know anything about the request variables, another way is to check the request method:
if (strtoupper($_SERVER['REQUEST_METHOD']) == 'POST')
正如评论中指出的那样,不仅要检查回发,而不仅仅是任何POST请求,都需要确保引荐来源网址与处理页面位于同一页面.像这样:
As pointed out in the comments, to specifically check for a postback and not just any POST request, you need to ensure that the referrer is the same page as the processing page. Something like this:
if (basename($_SERVER['HTTP_REFERER']) == $_SERVER['SCRIPT_NAME'])
这篇关于检查是否在PHP中发回了请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文