इस तरह
वास्तव में (MySQL ड्राइवर के लिए):
- प्रयास
mysql_real_escape_string()
(इस मामले समय के 99% हो जाएगा) यहाँ अन्य CodeIgniter सुरक्षा मदों के लिए लिंक है
- फॉल्स वापस
mysql_escape_string()
- फॉल्स के लिए वापस
addslashes()
- मैन्युअल निकल जाताकरने के लिए
str_replace()
https://github.com/EllisLab/CodeIgniter/blob/develop/system/database/drivers/mysql/mysql_driver.php#L294
/**
* Escape String
*
* @access public
* @param string
* @param bool whether or not the string will be used in a LIKE condition
* @return string
*/
function escape_str($str, $like = FALSE)
{
if (is_array($str))
{
foreach ($str as $key => $val)
{
$str[$key] = $this->escape_str($val, $like);
}
return $str;
}
if (function_exists('mysql_real_escape_string') AND is_resource($this->conn_id))
{
$str = mysql_real_escape_string($str, $this->conn_id);
}
elseif (function_exists('mysql_escape_string'))
{
$str = mysql_escape_string($str);
}
else
{
$str = addslashes($str);
}
// escape LIKE condition wildcards
if ($like === TRUE)
{
$str = str_replace(array('%', '_'), array('\\%', '\\_'), $str);
}
return $str;
}
ध्यान दें कि यह केवल पात्रों भागने है तो MySQL प्रश्नों को तोड़ने या कुछ अप्रत्याशित नहीं करेंगे, और एक डेटाबेस के संदर्भ में केवल प्रयोग किया जाता है के माध्यम सेऔर _
में LIKE
की स्थिति आप जो भी पास करते हैं उसके आधार पर सही वाक्यविन्यास सुनिश्चित करने के लिए क्वेरी करें।
कोई जादू किसी भी संदर्भ (एचटीएमएल, CSV या XML उत्पादन की तरह), और सिर्फ मामले में आप इसके बारे में सोच रहे थे के लिए सुरक्षित सभी डेटा करता है कि नहीं है: xss_clean()
एक एक आकार फिट सभी नहीं है समाधान और न ही यह 100% बुलेटप्रूफ है, कभी-कभी यह वास्तव में काफी अनुचित है। सक्रिय रिकॉर्ड क्लास स्वचालित रूप से बचने वाली क्वेरी करता है, लेकिन बाकी सब कुछ के लिए आपको दिए गए संदर्भ के सही तरीके से मैन्युअल रूप से डेटा को बचाना/स्वच्छ करना चाहिए, आउटपुट के साथ, इनपुट नहीं।
स्रोत
2011-11-05 15:45:59
सीआई के कोड को देखने पर विचार किया है? – Beat
बहुत सारी जानकारी: http://www.google.com.ng/search?gcx=c&sourceid=chrome&ie=UTF-8&q=codeigniter+sanitize+inputs%3F – Mob
पीडीओ कोई भी? http://www.php.net/pdo –