1

嗨,我有链接,其中有“和”,例如:http://site.com/?sd=text&sery=&son="><ic=x onerror="

<?
header("HTTP/1.1 301 Moved Permanently");
header("Location: http://site.com/?sd=text&sery=&son="><ic=x onerror=");
exit;
?>

如何正确编写脚本?

4

1 回答 1

6

您必须使用 php 的urlencode()函数对其进行 url 编码。这是在查询字符串中编码键和值的正确方法。您还必须使用前导反斜杠转义引号,以便它们包含在双引号字符串文字中。尝试这个:

<?
header("HTTP/1.1 301 Moved Permanently");
header("Location: http://site.com/?sd=text&sery=&son=" . urlencode("\"><ic=x onerror=\""));
exit;
?>

或者,在这种情况下,您可以单引号您的字符串文字,这将消除转义双引号的需要。注意:如果您对字符串进行单引号,则字符串中出现的任何撇号字符都需要使用前导反斜杠进行转义。尽管问题的标题和描述,我在您的示例中看不到任何内容。

<?
header('HTTP/1.1 301 Moved Permanently');
header('Location: http://site.com/?sd=text&sery=&son=' . urlencode('"><ic=x onerror="'));
exit;
?>
于 2012-11-20T16:58:05.303 回答