By adapting following method you can be stop your website from getting hacked,
Sanitizing and Validating users parameters: By a Sanitizing and Validating user the parameters before submitting them to the database can be reduce the chances of being attacked by SQL injection
Using Firewall: Firewall can be used to drop traffic from a suspicious IP address if attack is the simple DOS
Encrypting the Cookies: Cookie or Session poisoning can be prevented by a encrypting the content of cookies, associating cookies with a client IP address and timing out the cookies after some time
Validating and Verifying user input : This approach is ready to the prevent form tampering by verifying and validating the user input before processing it.
Validating and Sanitizing headers : This techniques is a useful against cross site scripting or XSS, this technique includes to validating and sanitizing headers, parameters passed via to URL, form parameters and hidden values to the reduce XSS attacks