Can anybody tell me how to prevent sql injection attack on a website..
Except where the query itself needs to be dynamically generated you should use prepare/bind so as to keep the SQL and the data separate.
Most instances where the query needs to be dynamically generated can also use prepare/bind although the coding can sometimes be a bit more complicated in order to map the data to the right places in the query.
The answers looks simple but its solution is very hard . Am still reseaching the same thing prevent attack by sql injection.
Thanks for the suggestion.
If you are reluctant from applying code based solutions for SQL Injection you can consider adding an external security layer like a web application firewall.
I am not sure if I can post direct links to commercial services. However, there is a new market of web security and performance cloud services. Most have some kind of free offering for small sites.
Instead of sending you links to the services (and probably getting nasty messages from the forum moderators) I am sending a link that reviews the two leading solutions in this space. You can choose for yourself.
Hope this helps.
What is so hard about using prepare and bind? For most queries it is no more complicated than the alternatives that are vulnerable to injection.
The only complication is when you are dynamically building the query that you need to dynamically build the parameter list for the bind at the same time.
The only part of a query that can't be made into data and passed in via the bind and which would therefore still be vulnerable is where you want to allow your visiitor to specify the table name - and that would be extremely rare.
ok .. thanks for your help felgall ......
one thinkg that will help is to check the data that i being send in the link, if you expect character (only) do a check if there are no numbers in it, if you expect numbers in your script do a check so it only accept numbers.
Its a simple addiion that dont take up much server time, tho at least help you protect something.
That test should have been done when the data is first read in - long before it is sent to the database (and done regardless of whether it is even to be sent to a database).
At best not validating the input data means that you waste time processing garbage.