Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/security/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 将未初始化的数据放入header()函数_Php_Security_Header_Sanitization - Fatal编程技术网

Php 将未初始化的数据放入header()函数

Php 将未初始化的数据放入header()函数,php,security,header,sanitization,Php,Security,Header,Sanitization,我是否因为没有过滤标题重定向中的数据而使我的站点容易受到攻击 例如: $foo = $_GET['foo']; header("Location: /bar.php?foo=$foo"); die(); 如果答案是肯定的,它们是什么类型的攻击,简单地用htmlentities逃逸数据是可行的解决方案吗 $foo = $_GET['foo']; $foo = htmlentities($foo); header("Location: /bar.php?foo=$foo"); die()

我是否因为没有过滤标题重定向中的数据而使我的站点容易受到攻击

例如:

$foo = $_GET['foo'];

header("Location: /bar.php?foo=$foo");

die();
如果答案是肯定的,它们是什么类型的攻击,简单地用htmlentities逃逸数据是可行的解决方案吗

$foo = $_GET['foo'];

$foo = htmlentities($foo);

header("Location: /bar.php?foo=$foo");

die();

URL参数不会被执行,因此您不会让自己受到攻击。但是,未能对数据进行编码可能会导致错误解释参数。您应该使用urlencode:


htmlentities不能清洁任何东西;它只编码在HTML中具有特殊意义的字符。因为这里没有HTML,所以这是毫无意义的。事实上,您可能会让情况变得更糟,因为HTML实体是用&..编码的,并且在URL中有它自己的特殊含义。请阅读并根据您提供的内容,我可以想出一些重定向的理由。听着,你只能重定向到一定数量的页面,执行类似于切换的操作,并确保完全控制重定向。@deceze谢谢你的建议。我现在将通读一遍。您应该使用urlencode对放入URL参数中的值进行编码。
$foo = urlencode($foo);
header("Location: /bar.php?foo=$foo");