2011-10-15 89 views
2

我接受來自TinyMCE的數據。我遇到困難時,我複製並粘貼到網站像這樣:SQL注入和轉義特殊字符

http://www.rlslog.net/category/games/pc/ 

我用下面的功能來防止SQL注入和特殊字符轉義,如果毀了我一次,我輸出的插入的文本整個頁面。

$title = mysql_real_escape_string($title); 
$data = mysql_real_escape_string($data); 
$author= mysql_real_escape_string($author); 

$data =htmlentities($data); 
$title =htmlentities($title); 
$author =htmlentities($author); 

mysql_query("SET NAMES 'utf8'"); 

mysql_query("INSERT INTO `easy_db`.`article` (`Title`, `Article`, `Topics`, `author`, `page`, tpage) VALUES('$title', '$data', '$topic', '$author', '$page','$tpage')") or die(mysql_error()); 
mysql_close(); 

我能得到什麼,當我輸出的數據是我的HTML文本(這心不是從數據庫中輸出)看起來就像是:

כותרת ×」×™×•× 

我turend magic_quotes_gpc的掉在我的php.ini

magic_quotes_gpc 
Default Value: Off 
Development Value: Off 
Production Value: Off 

這裏是文字如何,我把看起來在phpMyAdmin指的是當這樣的:

skidrow%2F&amp;layout=standard&amp;show_faces=false&amp;width=450&amp;action=like&amp;colorscheme=light&amp;height=35\" frameborder=\"0\" scrolling=\"no\"></iframe></p>\r\n<p class=\"comments_link\" style=\"padding-top: 20px; padding-right: 0px; padding-bottom: 10px; padding-left: 0px; line-height: 19px; margin: 0px;\"><a style=\"color: 

c02e13; text-decoration: none; padding: 0px; margin: 0px;\" title=\"Comment on Orcs Must Die Fix-SKIDROW\" 
href=\"http://www.rlslog.net/orcs-must-die-fix-skidrow/#respond\">Comments(0)</a></p>\r\n</div>\r\n</div>\r\n<div style=\"padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 40px; margin: 0px;\"><iframe style=\"padding: 0px; margin: 0px;\" src=\"http://www.roadcomponentsdb.com/300.htm\" frameborder=\"0\" marginwidth=\"0\" marginheight=\"0\" scrolling=\"NO\" width=\"300\" height=\"250\"></iframe></div>\r\n<p id=\"nextlinks\" style=\"padding-top: 20px; padding-right: 20px; padding-bottom: 0px; padding-left: 20px; margin: 0px;\"><strong style=\"padding: 0px; margin: 0px;\">Previous post:</strong>&nbsp;<a style=\"color: #c02e13; text-decoration: none; padding: 0px; margin: 0px;\" href=\"http://www.rlslog.net/musclemag-international-%e2%80%93-december-2011-p2p/\">MuscleMag International &ndash; December 2011-P2P</a></p> 

問題是爲什麼會發生?我如何防止它?我做足以防止SQL注入?

回答

2

SET NAMES 'utf8'正在改變你的數據。請參閱this MySQL forum link。他對發生了什麼提供了相當好的描述。簡短描述:轉換過程對於應該讀取字符的內容感到困惑。

+0

如果你看我的代碼,我已經設置它。有沒有另一種方法來編碼該字符串..任何PHP或MySQL函數來消除發生的影響 –

+0

@DmitryMakovetskiyd你必須刪除該語句。 –

+0

它似乎沒有任何改進,我仍然得到..×>ותרת×「×™×××除了文本我輸出 –