-2

I have a form with a text field a user can edit, which will create a page on the website containing the text entered. How can I ensure the resulting page doesn't show anything malicious, no links, images or code, just raw text? Currently from php I'm using htmlspecialchars(), and when displaying the text on the page it's within xmp tags. Is that enough, or should I explicitly do things like validating against script tags etc?

edit: This question is different to the suggested question, because I'm not using sql.

edit 2: I accepted strip_tags. I'm now validating user input from php with htmlspecialchars(strip_tags("input")), and wrapping in xmp tags when displayed.

jimmy
  • 3
  • 3

2 Answers2

0

First of all: use prepared statments for your database storing, updating etc etc...

Second: You should escape the output using htmlspecialchars() function, It will just convert special characters to HTML entities, so if you put a script tag in there, It will not run.

Unless you want your users to post code just like here in StackOverflow, you can just use strip_tags() function as @user2182349 pointed out.

Akar
  • 5,075
  • 2
  • 25
  • 39
0

You can use strip_tags - it will remove everything in tags. http://php.net/manual/en/function.strip-tags.php

user2182349
  • 9,569
  • 3
  • 29
  • 41