为什么 $_GET['name'] 什么都没有,当我导航到 http://example.com/test.php?<<<Apple>>>

why does $_GET['name'] is Nothing, when i navigate to http://example.com/test.php?&lt;&lt;&lt;Apple&gt;&gt;&gt;

我有一个使用 GET 方法获取变量的网站(假设它回复 http://example.com/test.php?id=Apple 之类的属性将 return Apple 的属性),并且它使用 $_GET['id'] php 中的全局变量,用于检索请求的 ID。

问题是每当我导航到该站点时

http://example.com/test.php?id=&amp;lt;&amp;lt;&amp;lt;Apple&amp;gt;&amp;gt;&amp;gt;

它只是不起作用,因为 $GET['id'] 是空的。为什么 ?

我必须使用 GET,因为我将与客户共享它,他们可以将其修改为他们想要的任何内容。如果我不能使用 GET,我有什么选择?

php 文件:

test.php

echo $_GET['id'];

$_GET['id'] 是空的,因为每次你输入 & 字符就像你在 url 添加另一个参数,所以如果你 print_r($_GET ) 你会看到类似这样的内容:

Array
(
    [id] => 
    [lt;] => 
    [lt;Apple] => 
    [gt;] => 
)

您可以尝试子字符串 $_SERVER['QUERY_STRING']。 在这种情况下,$_SERVER['QUERY_STRING'] 应该类似于 id=<<<Apple>>>,因此您可以 echo substr($_SERVER['QUERY_STRING'],3).