php $_GET 不工作
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11993730/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
$_GET not working
提问by user1604132
I cannot get my $_GET to work. It works on every other site I have on the server but just not on this site. The site is osCommerce and I am running PHP 5.
我无法让我的 $_GET 工作。它适用于我在服务器上的所有其他站点,但不适用于此站点。该网站是 osCommerce,我正在运行 PHP 5。
if (($HTTP_GET_VARS['image'] ==0) && ($products['products_image_lrg'] != '')) {
//do something
};
I also tried
我也试过
echo $_GET['image']
and it still will not work. It just gives me undefined index.
它仍然不起作用。它只是给了我未定义的索引。
The URL looks like this: /blah.php?image=2
网址如下所示: /blah.php?image=2
I have stripped the page down to the bare still not working see below
我已经将页面剥离到裸露的仍然无法正常工作见下文
<?php
echo $HTTP_GET_VARS['image'];
echo $_GET["image"];
echo "<br />";
?>
I get this
我明白了
Notice: Undefined variable: HTTP_GET_VARS in \popup_image.php on line 3 Notice: Undefined index: image in \popup_image.php on line 4
I have been doing some more digging and it looks like a problem somewhere in oscommerce not allowing it to read
我一直在做更多的挖掘,它看起来像是 oscommerce 某个地方的问题,不允许它读取
回答by paulsm4
the following shouldwork with PHP 5.x:
HTTP:
http://myserver/blah.php?image=2PHP (blah.php?):
if (isset($_GET['image'])) { $idx=$_GET['image']; // Should be "2" }
I'm assuming you're trying to access "$_GET[]" from "blah.php". If not, you need to pass the URL to the page you're calling.
print_r($_GET)orvar_dump($_GET)is a good idea. So is bumpingerror_reporting(NNN).An even betteridea is to create a dummy page, phpinfo.php:
phpinfo.php:
<?php phpinfo (); ?>http query:
http://myserver/phpinfo.php?image=2
Q: Does phpquery() show you the "image" URL anywhere???
Finally, here's a similar case that turned out to be a PHP install problem:
以下应该适用于 PHP 5.x:
HTTP:
http://myserver/blah.php?image=2PHP(blah.php?):
if (isset($_GET['image'])) { $idx=$_GET['image']; // 应该是“2” }
我假设您正在尝试从“blah.php”访问“$_GET[]”。如果没有,您需要将 URL 传递给您正在调用的页面。
print_r($_GET)或者var_dump($_GET)是个好主意。碰撞也是如此error_reporting(NNN)。一个更好的主意是创建一个虚拟页面 phpinfo.php:
phpinfo.php:
<?php phpinfo (); ?>http查询:
http://myserver/phpinfo.php?image=2
问:phpquery() 是否会在任何地方向您显示“图像”网址???
最后,这是一个类似的案例,结果证明是 PHP 安装问题:
回答by Matt R
You have forgotten to add the QSA (query string append)flag on your mod rewrite rule. Without this flag, any query string added to your url before the rewrite is discarded in favor of the new query string added to the rewrite rule, though it will still be visible in the bar at the top of the browser.
您忘记在 mod 重写规则中添加QSA(查询字符串附加)标志。如果没有这个标志,在重写之前添加到你的 url 的任何查询字符串都会被丢弃,以支持添加到重写规则的新查询字符串,尽管它仍然会在浏览器顶部的栏中可见。
回答by bobbiloo
First, try looking at an entire print out of the $_GET array:
首先,尝试查看 $_GET 数组的整个打印:
print_r($_GET);
回答by Jon
This is old, but I just stumbled upon the same problem and found an easy fix. I was using a short php tag (<?....?>). Once I changed it to <?php....?>, my $_GET started working again. I have no idea why only this was affected by the short tag, but it fixed. Hope this helps someone else...
这是旧的,但我偶然发现了同样的问题并找到了一个简单的解决方法。我使用的是一个简短的 php 标签 ( <?....?>)。一旦我将其更改为<?php....?>,我的 $_GET 又开始工作了。我不知道为什么只有这个受到短标签的影响,但它修复了。希望这对其他人有帮助...
回答by ElasticThoughts
is your 'image' a file? If so then it should be in $_FILESnot $_GET...
您的“图像”是文件吗?如果是这样,那么它应该$_FILES不是$_GET......
do print_r($_GET);and print_r($_FILES);
做print_r($_GET);和print_r($_FILES);
what do you see?
你看到了什么?
回答by ElasticThoughts
Kindly check your .htaccess also, maybe some rewrite rule there is destroying your GET parameters. See https://stackoverflow.com/a/6656450/216084
也请检查您的 .htaccess,也许那里的一些重写规则正在破坏您的 GET 参数。见https://stackoverflow.com/a/6656450/216084
回答by Goran
I always tend to use something like:
我总是倾向于使用类似的东西:
$image = isset($_GET['image']) ? $_GET['image'] : FALSE;

