为什么$_REQUEST在获取相同的参数时,在不同的情况下会返回不同的值?
我有两个 URL,其中包含参数“tour_date”,我试图在 PHP 中读出该参数。对第一个 URL:
.php?tour_id=336&tour_date=11/06/2010
运行 $_REQUEST["tour_date"]
返回值: 11/06/2010
而第二个 URL:
. php?tour_id=336&tour_date=11/06/2010
不返回任何内容。我已经运行了empty()方法来测试,它确实没有找到它。关于为什么会发生这种情况有什么想法吗?感谢您的帮助!
I have two URL's which contain the parameter "tour_date" which I am trying to read out in PHP. Running $_REQUEST["tour_date"]
for the first URL:
.php?tour_id=336&tour_date=11/06/2010
returns the value of: 11/06/2010
While the second URL:
.php?tour_id=336&tour_date=11/06/2010
returns nothing. I've run the empty() method to test, and it indeed is not finding it. Any ideas on why this would happen? Thanks for your help!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
$_REQUEST 是一个超全局变量,它结合了 $_GET、$_POST 和 $_COOKIE(默认按此顺序)
如果您的 POST 或 COOKIE 还将tour_date 设置为空字符串,则 REQUEST 值将被覆盖
$_REQUEST is a superglobal that combines $_GET, $_POST and $_COOKIE (in this order by default)
if your POST or COOKIE also set tour_date to an empty string, then the REQUEST values get overwritten
您可以尝试将
var_dump($_REQUEST);
放入代码中,看看这是否为您指明了正确的方向。另外,请确保您没有仅与单个“=”进行比较。
如
if($_REQUEST["tour_date"] = ""){
所示。这将返回 true 并将tour_date 设置为空。You could try putting
var_dump($_REQUEST);
in your code to see if that points you in the right direction.Also, make sure you don't have a comparison with only a single "=".
As in
if($_REQUEST["tour_date"] = ""){
. This will return true and also set tour_date to empty.