看板 PHP 關於我們 聯絡資訊
當我要執行SQL語法時,會用一個函數將POST進來的變數給包起來 函數長這樣: function GetSQLValueString($theValue, $theType){ $theValue=_addslashes($theValue); //會判斷magic_quotes_gpc再決定使用 //addslashes() switch ($theType) { case "text": //字串 case "date": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "long"://常整數 case "int": //整數 $theValue = ($theValue != "") ? intval($theValue) : "NULL"; break; case "double": //俘點數 $theValue = ($theValue != "") ? doubleval($theValue) : "NULL"; break; } return $theValue; } 所以出來的變數會將單引號(')、雙引號(")前面多加一個反斜線 但是後來GOOGLE才發現它也有漏洞似乎是中文編碼問題,單引號問題並沒有解決 請問這個函數該怎麼去補救? 先說感謝!! -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 123.0.232.61
showsky:可以使用 PDO 或者 mysqli 提供的 func 10/14 02:25
showsky:ref: http://ppt.cc/NZf8 10/14 02:25
guardlan:mysql_real_escape_string 10/14 15:22
MOONRAKER:好好的prepared statement不用偏自己硬幹出差不多的東東 10/14 22:07
因為本來的程式不是用pdo寫 現在轉pdo是個大工程..真沒辦法的話只好改了 ※ 編輯: PTTLSboy 來自: 123.0.232.61 (10/15 18:07)
MOONRAKER:OUCH :( 10/15 22:57
Bambe:還蠻想問這段code是哪裡的範例嗎 lol... 怎麼好像看到也有客 10/16 01:16
Bambe:戶的程式碼有看到類似的 lol 10/16 01:17
這段最原本是dreamweaver產生出來的,會把斜線給去除 加斜線那行是後來補上去的 ※ 編輯: PTTLSboy 來自: 220.128.117.43 (10/16 09:00)