Possible Duplicate:
What are the best practices for avoiding xss attacks in a PHP site
I have a <textarea> and an <input> for comments of my site.Obviously, I echo them in an interface page and inserting into my database.
I want to know what do I have to do, when a person injects (for example) a <img> to damage the page or sending a query to damage database?
What is a simple way?
I’ve tried to search < > ' " drop using but although I used \" instead of " but it doesn’t work and in PHP, I’ve got error.
Is searching these characters manually the best way (PHP and Javascript)?
What you are trying to acheive is to prevent a form of XSS (Cross site scripting attacks) attacks. You are trying to prevent the persistent variety:
There are numerous options to prevent them. OWASP has a neat explanation.. Go through it and find out. But mostly its a very big problem for an Individual to handle solely.
The best way is to use HTMLPurifier which is both simple and easy. It may be a bit slow. But the extra processing is worth it. To give you an example of how simple it is to use here is a basic code:
PS: HTMLPurifier has options to “whitelist”. Use that for your advantage.
EDIT:
To answer your question on stopping malformed SQL Injection attacks refer to this question: How can I prevent SQL injection in PHP? and this answer
Quote: