php防注入,表單提交值轉(zhuǎn)義的實現(xiàn)詳解
更新時間:2013年06月10日 08:26:29 作者:
本篇文章是對php防注入,表單提交值轉(zhuǎn)義的實現(xiàn)進(jìn)行了詳細(xì)的分析介紹,需要的朋友參考下
在開發(fā)時,我們要注意防止sql注入,所以在對表單提交過來的值要做相應(yīng)的處理,才可以把數(shù)據(jù)更新到數(shù)據(jù)庫里
php橫掃千軍函數(shù)。任何值都可以傳過來轉(zhuǎn)換
function quotes($content)
{
//如果magic_quotes_gpc=Off,那么就開始處理
if (!get_magic_quotes_gpc()) {
//判斷$content是否為數(shù)組
if (is_array($content)) {
//如果$content是數(shù)組,那么就處理它的每一個單無
foreach ($content as $key=>$value) {
$content[$key] = addslashes($value);
}
} else {
//如果$content不是數(shù)組,那么就僅處理一次
addslashes($content);
}
} else {
//如果magic_quotes_gpc=On,那么就不處理
}
//返回$content
return $content;
顯示的時候要用 stripslashes ()去掉反斜杠
stripslashes()了,它能把a(bǔ)ddslashes()處理時自動加上去的(反斜杠)\去掉
php橫掃千軍函數(shù)。任何值都可以傳過來轉(zhuǎn)換
復(fù)制代碼 代碼如下:
function quotes($content)
{
//如果magic_quotes_gpc=Off,那么就開始處理
if (!get_magic_quotes_gpc()) {
//判斷$content是否為數(shù)組
if (is_array($content)) {
//如果$content是數(shù)組,那么就處理它的每一個單無
foreach ($content as $key=>$value) {
$content[$key] = addslashes($value);
}
} else {
//如果$content不是數(shù)組,那么就僅處理一次
addslashes($content);
}
} else {
//如果magic_quotes_gpc=On,那么就不處理
}
//返回$content
return $content;
顯示的時候要用 stripslashes ()去掉反斜杠
stripslashes()了,它能把a(bǔ)ddslashes()處理時自動加上去的(反斜杠)\去掉
相關(guān)文章
php中\(zhòng)r \r\n \t的區(qū)別示例介紹
這篇文章主要介紹了php中\(zhòng)r \r\n \t的區(qū)別,需要的朋友可以參考下2014-02-02
PHP實現(xiàn)將漢字轉(zhuǎn)換為拼音及獲取詞語首字母的方法
這篇文章主要介紹了PHP實現(xiàn)將漢字轉(zhuǎn)換為拼音及獲取詞語首字母的方法,涉及php字符串、數(shù)組的遍歷及編碼轉(zhuǎn)換相關(guān)操作技巧,需要的朋友可以參考下2017-08-08

