Now there are 3 questions:
If I have the following HTML code that needs to be stored in a certain field in the database table, should I save it directly? Or do I need to encode it and then save it? Ask God for advice! If you want to encode, which method should be used? Please give me the specific code, thank you
<!-- JiaThis Button BEGIN -->
<script type="text/javascript" src="http://v3.jiathis.com/code/jiathis_r.js?move=0" charset="utf-8"></script>
<!-- JiaThis Button END -->
If I have a string in JSON format that I want to save to a field in a database table, do I need to encode it before saving it? Or deposit directly?
Is there anything else that should be paid attention to when storing data in the database? Please give me some advice, thank you
html
代码一般使用stripcslashes
对其片段转义入库,取出用addcslashes
还原,找一些开源的过滤xss
class library, such asIf it is a string in
JSON
format, just save it directlyAvoid
SQL
注入请使用PDO
preprocessing http://php.net/manual/zh/book...A simple post to prevent
XSS
First, introducing js into the code and directly storing it in the database without processing it is a very irrational behavior. Please solve it in the following way
1: Convert the information, htmlspecialchars, and html into entities, and then save them in the database. This method is lazy and easy to bypass
2: Use regular expressions to get the content of src and save it in the database