Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/228.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/77.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 在href上使用htmlspecialchars_Php_Html - Fatal编程技术网

Php 在href上使用htmlspecialchars

Php 在href上使用htmlspecialchars,php,html,Php,Html,为了保护我的网站免受XSS攻击,我在href上使用htmlspecialchars,如下所示: <a href="<?php echo htmlspecialchars($usersLink, ENT_QUOTES, 'UTF-8'); ?>">User&#039;s Link</a> 这种做法有什么问题吗? 它是否可能会使链接变形或失效?htmlspecialchars带有ENT\u引号,并且定义的字符编码应该是安全的,但对于URL而言,我建议

为了保护我的网站免受XSS攻击,我在href上使用
htmlspecialchars
,如下所示:

<a href="<?php echo htmlspecialchars($usersLink, ENT_QUOTES, 'UTF-8'); ?>">User&#039;s Link</a>

这种做法有什么问题吗?
它是否可能会使链接变形或失效?

htmlspecialchars
带有
ENT\u引号,并且定义的字符编码应该是安全的,但对于URL而言,我建议改为使用
urlencode
htmlspecialchars
entu引号,并且定义的字符编码应该是安全的,但对于URL,我建议改为使用
urlencode