我有2个字段( html form 中的文本框)user_name和password .
示例= <?php $mail = $_POST['mail']; $pswrd = $_POST['passwrd']; $addtouser = $mysqli->query("INSERT INTO
user_table (
电子邮件 ,
passwordss ) VALUES ('$mail', '$pswrd')"); ?>
如何 secure Password field 来自 SQL Injection 和 XSS (跨站点脚本)在php 5.6和mysql在 INSERT and select query ?
是密码字段接受所有特殊字符,如“,”,>等?
我是PHP的新手,我需要完整的示例代码和安全提示,以防止密码字段从SQL注入和xss .
抱歉打字不好 . 我是stackoverflow的新手 . 提前致谢 !!!
1 回答
准备好的语句是防止SQL注入的最佳方法之一 . i.e..xss,
使用 PDO ,看看这个页面
php.net/manual/en/pdo.prepared-statements.php
PHP's input filters
https://coding.smashingmagazine.com/2011/01/keeping-web-users-safe-by-sanitizing-input-data/
sanitization functions
http://php.net/manual/en/filter.filters.php
similimar question:
What's the best method for sanitizing user input with PHP?
What are the best PHP input sanitizing functions? How can I prevent SQL injection in PHP?