Jump to content

sanitize input


n00bl337

Recommended Posts

It all really depends on how you are going to use the data. You *can* allow the user to input anything and still prevent SQL injection, cross site scripting, and just plain old HTML display issues.

 

When saving the data to the database you should always be escaping the input to prevent SQL injection. For MySQL databases you would use mysql_real_escape_string().

 

When you display the input (if you don't restring the input) you could use htmlenteties() or htmlspecialcharacters() to escape characters that would cause problems in the rendered HTML. You would use strip tags if you really, really don't want the user to input that data.

 

For example, if I put <b>text</b> in this forum post it will not display as bold text. The tags are still being saved to the database, but it is being escaped so it will not be rendered as HTML tags.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.