Php rawurlencode验证

Php rawurlencode验证,php,Php,我有一种感觉,我做得太过分了,但只是为了防止xss和其他人 <?php //will pass as get parameter to a another page header("Location: /nextpage?p=". rawurlencode(strip_tags(htmlspecialchars($_SERVER['REQUEST_URI'])))); ?> strip\u标记在示例代码中没有注释。一旦对html特殊字符进行编码,字符串中将不再有任何合法的htm

我有一种感觉,我做得太过分了,但只是为了防止xss和其他人

<?php
//will pass as get parameter to a another page
header("Location: /nextpage?p=". rawurlencode(strip_tags(htmlspecialchars($_SERVER['REQUEST_URI']))));

?>


strip\u标记在示例代码中没有注释。一旦对html特殊字符进行编码,字符串中将不再有任何合法的html标记。这里可能只需要url编码。我只会在将特殊字符放入数据库之前或在输出到页面时对其进行编码。是的,这真的太多了。只需做一个简单的
标题(“位置:/nextpage?p=“.filter_输入(输入服务器,'REQUEST_URI',filter_SANITIZE_ENCODED))
并成为一名快乐的程序员。谢谢,但是为什么我的请求URI总是在URL的开头添加一个/呢?filter\u input(输入服务器,basename($\u SERVER['REQUEST\u URI']),filter\u SANITIZE\u ENCODED)----这有效吗?