• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

Question PHP: Am I using htmlspecialchars correctly?

I am not an experienced web developer, I have a smattering of experience in ASP and PHP.

My business's contact form page is currently written in ASP which works on my old (Windows) server, and I'm rewriting it in PHP for my new (Linux) server.

There are three fields to the form: name, contact method, message. I'm not doing anything special with these fields (though in ASP I did add a bit to stop spammers from sending web page links), the form contents just gets e-mailed to me. There's a small bit of form validation to ensure that all three fields have to have some content in otherwise the form won't submit successfully.

I used htmlspecialchars on all three fields before the content gets e-mailed to me; my understanding of input sanitisation is a basic awareness of xkcd #327 as well as the rough outline of what XSS attacks are about. My grasp of this topic makes me think that this is a good idea because in theory someone could try to send a web page exploit via e-mail, but also maybe to stop crap being sent into php that could exploit it.

Am I correct, or do I have the wrong end of the stick?
 
Back
Top