gpt4 book ai didi

php - 我应该在所有输出上使用 htmlentities() 吗? (防止XSS攻击)

转载 作者:可可西里 更新时间:2023-11-01 08:06:35 27 4
gpt4 key购买 nike

<分区>

Possible Duplicate:
What are the best practices for avoiding xss attacks in a PHP site
What are the common defenses against XSS?

我正在尝试使我编写的 PHP 应用程序安全,但对转义输出有疑问。一旦我了解到这样做可以防止 SQL 注入(inject),我就转而使用带有 PDO 的准备好的语句,而且似乎另一种主要的攻击类型是 XSS。我像这样为我的页面构建输出(假设变量中包含来自数据库的数据):

$output = '';

$output .= '
<div style="float: left; width: 800px;">
<span>Name:</span><span> ' . $name . '</span>
<span>Address:</span><span>' . $addr . '</span>
<span>Time:</span><span>' . time() . '</span>
</div>';

$output .='[lots more html]';

所以,我的问题是,我是否应该在输出数据库中的每条数据周围使用 htmlentities()(一个典型的页面有几十个,有的可能是数百个来自正在输出的数据库的变量)?

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com