MySQL Forums
Forum List  »  PHP

Re: Text box security
Posted by: Rick James
Date: February 08, 2011 11:02AM

This will keep the INSERT from stumbling and prevent "SQL Injection":
$fantasy = mysqli_real_escape_string ($dbc, $trimmed['aboutme']);

This will prevent JavaScript injection (by disallowing '<'), limit the length, etc:
if (preg_match ('/^[0-9A-Za-z \'.-]{0,160}$/i', $trimmed['aboutme'])) {
(Minor note: The "i" is redundant with "A-Za-z".)

So, sounds pretty good.

It sound be safe now to SELECT, then echo, the field.

Less aggressive would be to apply htmlentities() to anything echoed. You could then allow '<' to be entered, yet still prevent it from causing trouble on the subsequent web page. (Note '<' would be stored as itself in the database table, and modified only during display.) With that, you could skip the preg_match.

Another caveat with your code: You are assuming unaccented English only? Accents will be disallowed.

Options: ReplyQuote


Subject
Written By
Posted
February 06, 2011 12:30AM
Re: Text box security
February 08, 2011 11:02AM
February 08, 2011 02:27PM
February 10, 2011 03:10AM
February 08, 2011 06:57PM
February 08, 2011 07:49PM
February 08, 2011 08:21PM
February 08, 2011 10:21PM
February 08, 2011 11:52PM
February 09, 2011 11:40AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.