Forum Moderators: coopster
After I strip out "nasty" html tags (<script>,eval, etc.), is running
htmlentities($textarea_clean,ENT_QUOTES)sufficient to prevent injection attacks?
If I run mysql_real_escape_string() then my output ends up with "\n\r" all over it, stripslashing them just makes them "nr"
I can tell I'm missing something, but not sure what it is. :/
<textarea>that could include HTML. I want to insert their data into a MySQL database.
However, I want to preserve their newlines and other data entry precisely so it can be echoed back into a
<textarea>for future editing.
Seems that just running
mysql_real_escape_string()when inserting then
stripslashes()when echoing ends up turning newlines "\n\r" into the actual text string "\n\r"
What I have working well right now is that I
htmlentities($str, ent_quotes)when inserting, then I use
html_entity_decode($str,ENT_NOQUOTES)to display the data inline, and just echo the
$strwhen putting it into a
<textarea>for editing.
What I don't know is this:
A) Secure?
B) Best Practices?
Added: Thanks for fixing my title! :)
Retrieving and displaying data for editing in a textarea:
Retrieving and displaying data as an HTML page:
The only issue you may have is how your server is configured to handle Magic Quotes [php.net]. Both of them off is best.
Here's my test string:
<h5>"Testing"</h5><p>This is some text, don't misconstrue it's purpose.</p>
How it looks in my DB after I run mysql_real_escape_string() and INSERT it:
<h5>\"Testing\"</h5>\r\n\r\n<p>This is some text, don\'t misconstrue it\'s purpose.</p>
When I SELECT it then either echo or print it, I get:
<h5>\"Testing\"</h5>\r\n\r\n<p>This is some text, don\'t misconstrue it\'s purpose.</p>
If I stripslashes() then print, I get:
<h5>"Testing"</h5>rnrn<p>This is some text, don't misconstrue it's purpose.</p>
So even though magic quotes is Off, it still looks like it's on. :(
I had just started using a PHP Class a few days ago to connect to and do all my database work. It runs mysql_real_escape_string() as part of it's default insert() function. Everything is working now that I've adjusted my scripts.
Sorry for wasting your time coopster. :(