开发者

Best practices for making code string safe for database & output

开发者 https://www.devze.com 2023-02-09 15:24 出处:网络
I am currently working on a project that saves code snippets to a database, which can be viewed and copied later. I just wanted to know the best way to check the input would be safe from SQL injection

I am currently working on a project that saves code snippets to a database, which can be viewed and copied later. I just wanted to know the best way to check the input would be safe from SQL injection and XSS, CSRF on the cli开发者_如何学编程ent side when viewed.

I know the string will have to be converted, but in not sure which is the best method.

Any links or examples would be great.

Thanks


XSS: http://php.net/manual/en/function.htmlspecialchars.php
SQLI: http://php.net/manual/en/function.mysql-real-escape-string.php
CSRF: you should generate token or at least check referrer.

In addition, valid the input type, i.e if its suppose to be numeric value, use intval($input), and so on.

0

精彩评论

暂无评论...
验证码 换一张
取 消