嗨,我有链接,其中有"和",例如: 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;
?>
Run Code Online (Sandbox Code Playgroud)
如何正确编写脚本?
你必须使用php的urlencode()函数对其进行url编码.这是在查询字符串中对键和值进行编码的正确方法.您还必须使用前导反斜杠转义引号,以便将它们包含在双引号字符串文字中.试试这个:
<?
header("HTTP/1.1 301 Moved Permanently");
header("Location: http://site.com/?sd=text&sery=&son=" . urlencode("\"><ic=x onerror=\""));
exit;
?>
Run Code Online (Sandbox Code Playgroud)
或者,在这种情况下,您可以单引引字符串文字,这将消除转义双引号的需要.注意:如果单引号字符串,则字符串中出现的任何撇号字符都需要使用前导反斜杠进行转义.尽管问题的标题和描述,我在你的例子中没有看到任何内容.
<?
header('HTTP/1.1 301 Moved Permanently');
header('Location: http://site.com/?sd=text&sery=&son=' . urlencode('"><ic=x onerror="'));
exit;
?>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
69 次 |
| 最近记录: |