用PHP清理用户输入的方法有哪些?
在PHP中,对输入进行消毒是一个有趣的概念。清理意味着将输入中的未授权字符转义。让我们学习一些最佳实践,以安全可靠的方式处理输入。
在mysqli语句中使用real_escape_string()函数。
示例
<?php
$conn= new mysqli("localhost", "root","","testdb");
$street = $conn->real_escape_string($_POST['street']);
?>我们可以htmlentities()在数据库中插入数据并在浏览器中显示时使用和html_entity_decode()。
示例
<?php $data['message'] = htmlentities($message);//at the time of insert in database echo html_entity_decode($data['message']); //at the time of display in browser ?>
在命令提示符下,使用escapeshellarg清理用户输入。
示例-
<?php system('ls '.escapeshellarg($data['dir']));?>热门推荐
10 新年门口花束祝福语简短
11 盘锦结婚祝福语大全简短
12 父母生日祝福语 简短独特
13 家庭恩爱祝福语简短英文
14 高考俄语祝福语大全简短
15 虎年祝福语 诗句唯美简短
16 生日婚礼祝福语简短精辟
17 虎年喝酒拜年祝福语简短
18 教师闺蜜祝福语简短