| | #1 |
| HyperActive Warrior War Room Member Join Date: 2009 Location: Living between LA & SD
Posts: 205
Thanks: 27
Thanked 36 Times in 33 Posts
|
So I have a battle royal going on here... I've got a php page, trying to insert into a MySQL db from an HTML textarea. Everything works grand, except when I have single quotes (') in the textarea. I've checked the php.ini file and magic quotes are all OFF. magic_quotes_gpc = Off magic_quotes_runtime = Off magic_quotes_sybase = Off Anyone know what's going on, and how I can fix it? Thanks for your help... |
| |
| | #2 |
| Web Developer Join Date: 2010 Location: Wisconsin
Posts: 322
Thanks: 2
Thanked 80 Times in 74 Posts
|
I can't think of any reason you would do this other than storing source code... Your basically creating a time bomb if anyone from the public has a chance to access this form. Your having issue with single quotes because you are injecting into the query. You need to build some security into this and you wont have the issue. addslashes($str); mysql_real_escape($str); htmlentities($str); I would even go all out and do a str_replace() and preg_match() on some parts of the input and clean it further. Then when it comes out, to display, do everything in reverse. But like I said, Time Bomb, you really have to check and double check this input when allowing any type of user input into the database. If there is a hole, some hacker will find it one day. |
| | |
| |
| The Following User Says Thank You to phpbbxpert For This Useful Post: |
| | #3 |
| VIP Warrior War Room Member Join Date: 2008 Location: Montreal Canada
Posts: 2,390
Thanks: 1,017
Thanked 836 Times in 572 Posts
Blog Entries: 1 |
One thing you can do when storing raw HTML into a MySQL database is encode it to remove the "special " HTML characters, including the single-quote. When retrieving teh data you decode it to get back the original HTML string. These two PHP functions will help you out: PHP htmlspecialchars() Function PHP htmlspecialchars_decode() Function Hope this helps! Bill |
| |
| The Following User Says Thank You to ereadergold For This Useful Post: |
| | #4 |
| HyperActive Warrior War Room Member Join Date: 2009 Location: Living between LA & SD
Posts: 205
Thanks: 27
Thanked 36 Times in 33 Posts
|
Thanks for the help. I'm actually only using it in development through xampp. But this does make want to go back through some other scripts and make them more secure... I appreciate it.. |
| |
| | #5 |
| Warrior Member Join Date: 2009
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
|
if you are concerned with security you may try htmlPurifier and PDO (parameter binding when you write to DB)
|
| |
|
| Bookmarks |
| Tags |
| <textarea>, <textarea>, mysql, php |
| |