I'll recommed you to study the guidelines of OWASP, which will teach you how security works in detail and also how to implement them. In the following link some information about XSS protection is shared: https://www.owasp.org/index.php/XSS_(Cro...heat_Sheet
There are tons of ways to secure your website and implement different techniques. Do you have some doubts or a specific question, feel free to ask them here. Personally (regardless of the programming language) I always search on Google, and specifically on StackOverflow, e.g.: Use prepared statements and parameterized queries: https://stackoverflow.com/questions/6017...ion-in-php