Correct way to sanitize input in MySQL using PDO

前端 未结 3 1425
被撕碎了的回忆
被撕碎了的回忆 2021-01-01 02:03

so I had a friend of mine try to run a SQLinjection on my site and he managed to get into it using the code underneath. How can I prevent this? I have read something about s

3条回答
  •  梦毁少年i
    2021-01-01 02:41

    Don't sanitize input. Just make sure that you really write to the database what ever data is provided (i.e. protect against SQL injection) and then escape your output.

    To protect against SQL injection, use bound parameters. To escape your output, use htmlspecialchars on web pages and any other encoding appropriate given the medium you are outputting to.

    Just remember that you have to do both of the above. If you only protect against SQL injection attacks, you'll still leave your site wide open to XSS attacks.

提交回复
热议问题