I have created a very basic commenting system that allows users to comment. The problem is that some malicious uses can try to write some HTML or JavaScript inside the comments. If the comments get published, will that JavaScript be able run on other user's devices? I can take care of the JavaScript when I check the comments on server side.
However, I still don't know how to deal with PHP inside the comments. Let's say someone includes a PHP script inside the comments. I think that as soon as I start parsing the comment on my server to remove malicious content. The PHP script inside the comment will start running and mess the whole thing up. Am I right?
Is there any way I can sanitize PHP inside the comments? If the PHP posted by a user in a comment runs on my server won't I be in trouble?
Let's say a user enters the following comment:
unlink(glob(*.php));
and I do the following inside my comment parsing script:
$comment = $_POST['comment'];
Am I in trouble?
Am I making the question clear? Let me know if I need to add anything.