用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']));?>热门推荐
1 带狗狗训练
4 听力训练狗狗
6 怎训练狗狗
7 腹肌训练狗狗
8 网球训练狗狗
9 记叙文训练狗狗
10 狗狗太凶怎么训练
11 核心力量训练狗狗
12 狗狗乱叫怎么训练
13 发音训练狗狗
14 怎么训练狗狗叼东西给主人
15 荆州训练狗狗
16 篮球训练狗狗
17 做训练狗狗
18 训练狗狗坐姿