Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

PHP

Jackie Jen
Jackie Jen
2,723 Points

Cross Site Scripting (XSS) Attacks

I have search about what is Cross Site Scripting (XSS) Attacks. But mostly is talking how they steal the session or cookies of user. It did not show an example on how to prevent it.

Is there any example show that how to prevent Cross Site Scripting (XSS) Attacks ?

2 Answers

Michael Bianchi
Michael Bianchi
2,488 Points

Most of your hacking attacks rely on lay users not knowing what to do (social engineering). Get into the practice of form validation and force the user to enter critical items (like passwords) in a certain context (example: don't allow special characters in your forms). PHP and MySQL are especially vulnerable to Injection attacks - keep in mind that 50% of websites are attacked with SQL injection. It can even be used to take over a server and yet it's totally preventable with form validation. PHP 5+ (maybe an earlier version, too, not sure) offers escape characters that treat the backslash, comment characters and quotes in a text field as text and NOT PHP commands - this is useful.