如何检查 *any* GET 字段是否已填充 html php

How to check if *any* GET field is populated html php

情况:试图防止基于 DOM 的 XSS.

我的解决方案:检查是否填充了任何 GET 字段,因为大多数基于 DOM 的 XSS 附加到 URL 的末尾,例如 https://example.com/page?<script>XSS</script>

问题:有什么方法可以检查 "?" 之后是否有任何内容,通常包含 $_GET 字段。

其他信息:我尝试 $_GET['']."%" 试图找出那里的任何东西,但没有用。

您可以使用 $_GET。只需 print_r($_GET); 如果您在查询字符串中有任何内容?然后数据将在 $_GET 数组中。如果 $_GET 数组为空则查询字符串中没有数据

echo "<pre>";
print_r($_GET); 
echo "</pre>";

转到http://php.net/manual/en/reserved.variables.get.php

有几种可能的方法..例如:

您可以遍历 $_GET

 foreach( $_GET as $key => $value) {

  // if any you can perform your check 

 }

或者您可以检查

  if (isset($_GET) {

   count($_GET) ;   // the you know the number of elemns
 }

这就是我使用 http://domain.tld/page?<script>XSS</script> 时出现的结果。

$_GET不是你说的空

只需迭代每个 $_GET 属性,并确保在使用您的业务模型进行任何数据处理之前对它们进行清理。

foreach ($_GET as $key => $attribute)
{
    // do something with $key or $attribute!
}