用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 婆婆高寿祝福语大全简短