先看下手冊(cè)上怎么說(shuō)的吧!

對(duì)一般人來(lái)說(shuō)看下前兩段就可以了

Magic Quotes

代碼: Magic Quotes is a process that automagically escapes incoming " /> 99成人免费视频,手机在线观看毛片,日韩视频www

一区二区久久-一区二区三区www-一区二区三区久久-一区二区三区久久精品-麻豆国产一区二区在线观看-麻豆国产视频

php magic_quotes_gpc的一點(diǎn)認(rèn)識(shí)與分析

blankyao 說(shuō)“學(xué)習(xí)的過(guò)程就是不斷的發(fā)現(xiàn)錯(cuò)誤,不斷的改正錯(cuò)誤”;

先看下手冊(cè)上怎么說(shuō)的吧!

對(duì)一般人來(lái)說(shuō)看下前兩段就可以了

Magic Quotes

代碼:
Magic Quotes is a process that automagically escapes incoming data to the php script. It's preferred to code with magic quotes off and to instead escape the data at runtime, as needed.
What are Magic Quotes


代碼:
When on, all ' (single-quote), " (double quote), / (backslash) and NULL characters are escaped with a backslash automatically. This is identical to what addslashes() does.

There are three magic quote directives:
magic_quotes_gpc

代碼:
Affects HTTP Request data (GET, POST, and COOKIE). Cannot be set at runtime, and defaults to on in php.
magic_quotes_runtime

代碼:
If enabled, most functions that return data from an external source, including databases and text files, will have quotes escaped with a backslash. Can be set at runtime, and defaults to off in php.
magic_quotes_sybase

代碼:
If enabled, a single-quote is escaped with a single-quote instead of a backslash. If on, it completely overrides magic_quotes_gpc. Having both directives enabled means only single quotes are escaped as ''. Double quotes, backslashes and NULL's will remain untouched and unescaped.
Why use Magic Quotes




1 Useful for beginners

Magic quotes are implemented in php to help code written by beginners from being dangerous. Although SQL Injection is still possible with magic quotes on, the risk is reduced.

2Convenience

For inserting data into a database, magic quotes essentially runs addslashes() on all Get, Post, and Cookie data, and does so automagically.


Why not to use Magic Quotes




1 Portability

代碼:
Assuming it to be on, or off, affects portability. Use get_magic_quotes_gpc() to check for this, and code accordingly.
2 Performance

代碼:
Because not every piece of escaped data is inserted into a database, there is a performance loss for escaping all this data. Simply calling on the escaping functions (like addslashes()) at runtime is more efficient.

Although php.ini-dist enables these directives by default, php.ini-recommended disables it. This recommendation is mainly due to performance reasons.
3 Inconvenience

代碼:
Because not all data needs escaping, it's often annoying to see escaped data where it shouldn't be. For example, emailing from a form, and seeing a bunch of /' within the email. To fix, this may require excessive use of stripslashes().
這些英文實(shí)在是需要像我這類人有足夠的耐心啊(不是說(shuō)我有耐心,而是我英語(yǔ)爛),剛才也說(shuō)了,對(duì)于一般人只看下前兩段就可以了,特別是我用紅色標(biāo)出來(lái)的字!!!

另外,特別注意的是,魔術(shù)引用發(fā)生作用是在傳遞$_GET,$_POST,$_COOKIE時(shí)

下面是案例

代碼:
1.
條件: magic_quotes_gpc=off
寫入數(shù)據(jù)庫(kù)的字符串未經(jīng)過(guò)任何過(guò)濾處理。從數(shù)據(jù)庫(kù)讀出的字符串也未作任何處理。

數(shù)據(jù):  $data="snow''''sun" ; (snow和sun之間是四個(gè)連續(xù)的單引號(hào)).

操作: 將字符串:"snow''''sun" 寫入數(shù)據(jù)庫(kù),

結(jié)果: 出現(xiàn)sql語(yǔ)句錯(cuò)誤,mysql不能順利完成sql語(yǔ)句,寫入數(shù)據(jù)庫(kù)失敗。

數(shù)據(jù)庫(kù)保存格式:無(wú)數(shù)據(jù)。

輸出數(shù)據(jù)格式:無(wú)數(shù)據(jù)。

說(shuō)明: 對(duì)于未經(jīng)處理的單引號(hào)在寫入數(shù)據(jù)庫(kù)時(shí)會(huì)使sql語(yǔ)句發(fā)生錯(cuò)誤。

代碼:
2.
條件: magic_quotes_gpc=off
寫入數(shù)據(jù)庫(kù)的字符串經(jīng)過(guò)函數(shù)addslashes()處理。從數(shù)據(jù)庫(kù)讀出的字符串未作任何處理。

數(shù)據(jù):  $data="snow''''sun" ; (snow和sun之間是四個(gè)連續(xù)的單引號(hào)).

操作: 將字符串:"snow''''sun" 寫入數(shù)據(jù)庫(kù),

結(jié)果: sql語(yǔ)句順利執(zhí)行,數(shù)據(jù)成功寫入數(shù)據(jù)庫(kù)

數(shù)據(jù)庫(kù)保存格式:snow''''sun (和輸入一樣)

輸出數(shù)據(jù)格式:snow''''sun (和輸入一樣)

說(shuō)明: addslashes()函數(shù)將單引號(hào)轉(zhuǎn)換為/'的轉(zhuǎn)義字符使sql語(yǔ)句成功執(zhí)行,
但/'并未作為數(shù)據(jù)存入數(shù)據(jù)庫(kù),數(shù)據(jù)庫(kù)保存的是snow''''sun 而并不是我們想象的snow/'/'/'/'sun

代碼:
3.
條件: magic_quotes_gpc=on
寫入數(shù)據(jù)庫(kù)的字符串未經(jīng)過(guò)任何處理。從數(shù)據(jù)庫(kù)讀出的字符串未作任何處理。

數(shù)據(jù):  $data="snow''''sun" ; (snow和sun之間是四個(gè)連續(xù)的單引號(hào)).

操作: 將字符串:"snow''''sun" 寫入數(shù)據(jù)庫(kù),

結(jié)果: sql語(yǔ)句順利執(zhí)行,數(shù)據(jù)成功寫入數(shù)據(jù)庫(kù)

數(shù)據(jù)庫(kù)保存格式:snow''''sun (和輸入一樣)

輸出數(shù)據(jù)格式:snow''''sun (和輸入一樣)

說(shuō)明: magic_quotes_gpc=on 將單引號(hào)轉(zhuǎn)換為/'的轉(zhuǎn)義字符使sql語(yǔ)句成功執(zhí)行,
但/'并未作為數(shù)據(jù)入數(shù)據(jù)庫(kù),數(shù)據(jù)庫(kù)保存的是snow''''sun而并不是我們想象的snow/'/'/'/'sun。

代碼:
4.
條件: magic_quotes_gpc=on
寫入數(shù)據(jù)庫(kù)的字符串經(jīng)過(guò)函數(shù)addlashes()處理。從數(shù)據(jù)庫(kù)讀出的字符串未作任何處理。

數(shù)據(jù):  $data="snow''''sun" ; (snow和sun之間是四個(gè)連續(xù)的單引號(hào)).

操作: 將字符串:"snow''''sun" 寫入數(shù)據(jù)庫(kù),

結(jié)果: sql語(yǔ)句順利執(zhí)行,數(shù)據(jù)成功寫入數(shù)據(jù)庫(kù)

數(shù)據(jù)庫(kù)保存格式:snow/'/'/'/'sun (添加了轉(zhuǎn)義字符)

輸出數(shù)據(jù)格式:snow/'/'/'/'sun (添加了轉(zhuǎn)義字符)

說(shuō)明: magic_quotes_gpc=on 將單引號(hào)轉(zhuǎn)換為/'的轉(zhuǎn)義字符使sql語(yǔ)句成功執(zhí)行,
addslashes又將即將寫入數(shù)據(jù)庫(kù)的單引號(hào)轉(zhuǎn)換為/',后者的轉(zhuǎn)換被作為數(shù)據(jù)寫入
數(shù)據(jù)庫(kù),數(shù)據(jù)庫(kù)保存的是snow/'/'/'/'sun
總結(jié)如下:

1. 對(duì)于magic_quotes_gpc=on的情況,

我們可以不對(duì)輸入和輸出數(shù)據(jù)庫(kù)的字符串?dāng)?shù)據(jù)作
addslashes()和stripslashes()的操作,數(shù)據(jù)也會(huì)正常顯示。

如果此時(shí)你對(duì)輸入的數(shù)據(jù)作了addslashes()處理,
那么在輸出的時(shí)候就必須使用stripslashes()去掉多余的反斜杠。

2. 對(duì)于magic_quotes_gpc=off 的情況

必須使用addslashes()對(duì)輸入數(shù)據(jù)進(jìn)行處理,但并不需要使用stripslashes()格式化輸出
因?yàn)閍ddslashes()并未將反斜杠一起寫入數(shù)據(jù)庫(kù),只是幫助mysql完成了sql語(yǔ)句的執(zhí)行。

補(bǔ)充:

magic_quotes_gpc 作用范圍是:WEB客戶服務(wù)端;作用時(shí)間:請(qǐng)求開(kāi)始時(shí),例如當(dāng)腳本運(yùn)行時(shí).
magic_quotes_runtime 作用范圍:從文件中讀取的數(shù)據(jù)或執(zhí)行exec()的結(jié)果或是從SQL查詢中得到的;作用時(shí)間:每次當(dāng)腳本訪問(wèn)運(yùn)行狀態(tài)中產(chǎn)生的數(shù)據(jù)

php技術(shù)php magic_quotes_gpc的一點(diǎn)認(rèn)識(shí)與分析,轉(zhuǎn)載需保留來(lái)源!

鄭重聲明:本文版權(quán)歸原作者所有,轉(zhuǎn)載文章僅為傳播更多信息之目的,如作者信息標(biāo)記有誤,請(qǐng)第一時(shí)間聯(lián)系我們修改或刪除,多謝。

主站蜘蛛池模板: 99精品视频在线观看 | 激情6月丁香婷婷色综合 | 国产91中文剧情在线观看 | 国内第一永久免费福利视频 | 国产精品91在线播放 | 精品免费久久 | 99国产精品高清一区二区二区 | 免费一区二区视频 | 国产成人亚洲精品91专区手机 | 国产成人一区二区视频在线观看 | 日本国产最新一区二区三区 | 日本永久免费 | 国产高清网址 | 久久精品a| 999精品免费视频观看 | 精品精品国产高清a毛片牛牛 | 伊人五月婷婷 | 国产高跟黑色丝袜在线 | 亚洲天堂视频在线观看 | 四虎网站在线 | 国产91第一页 | 日本欧美久久久久免费播放网 | 肉色丝袜一区二区高跟鞋 | 国产美女一级片 | 国产成人mv在线观看入口视频 | 五月天综合激情网 | 国产全黄一级毛片 | 国产精品久久久久无码av | 精品三区 | 国产女人视频 | 激情五月综合网 | 图片区小说区欧洲区 | 亚洲精品9999久久久久 | 91av综合| 欧美人体一区二区三区 | 国产精品播放 | 久久这里一区二区精品 | 正在播放一区二区 | 五月婷婷综合在线 | 日韩中文字幕免费版 | 狠狠网 |