Jump to content

* form manipulation - a security Question


unistake

Recommended Posts

Hi all,

 

I have heard stories that hackers/viruses or basically something that you don't want uploaded to a server through a website form have been able to type some sort of code in to a html form field to access information.

 

I know how to control the length of fields, how to validate that an email address is in the correct format etc. - but when it comes to having a textfield for the user to add up to 2000 characters of their own words, how can I protect from malicious code being inserted?

 

The textfield is located inside the user area but anyone can join, so anyone ultimately can enter code!

 

Thanks for the help. 

Link to comment
Share on other sites

Since it's string data, you'll want to use mysql_real_escape_string() (or mysqli_real_escape_string if you're using the mysqli extensions) to escape characters that would be used in sql injection attacks. Note that you need a connection established to the database for mysql_real_escape_string() to work.

 

mysql_connect( details, etc.);

$textarea = mysql_real_escape_string($_POST['textarea']);

 

"INSERT INTO table (field) VALUES ($textarea)";

 

When you retrieve and display the data, that is when you'd need to use a function such as htmlentities(), and/or possibly strip_tags() to help prevent XSS exploits.

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.