[請益] SQL字串中的變數處理,該怎麼做最好
當我要執行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
推
10/14 02:25, , 1F
10/14 02:25, 1F
→
10/14 02:25, , 2F
10/14 02:25, 2F
→
10/14 15:22, , 3F
10/14 15:22, 3F
→
10/14 22:07, , 4F
10/14 22:07, 4F
因為本來的程式不是用pdo寫
現在轉pdo是個大工程..真沒辦法的話只好改了
※ 編輯: PTTLSboy 來自: 123.0.232.61 (10/15 18:07)
→
10/15 22:57, , 5F
10/15 22:57, 5F
推
10/16 01:16, , 6F
10/16 01:16, 6F
→
10/16 01:17, , 7F
10/16 01:17, 7F
這段最原本是dreamweaver產生出來的,會把斜線給去除
加斜線那行是後來補上去的
※ 編輯: PTTLSboy 來自: 220.128.117.43 (10/16 09:00)
PHP 近期熱門文章
PTT數位生活區 即時熱門文章