先看下手冊上怎么說的吧!

對一般人來說看下前兩段就可以了

Magic Quotes

代碼: Magic Quotes is a process that automagically escapes incoming " /> 恋夜影视列表免费安卓手机版 ,yellow2019在线观看视频,国产一卡2卡3卡4卡孕妇网站

天天躁日日躁狠狠躁AV麻豆-天天躁人人躁人人躁狂躁-天天澡夜夜澡人人澡-天天影视香色欲综合网-国产成人女人在线视频观看-国产成人女人视频在线观看

php magic_quotes_gpc的一點認識與分析

blankyao 說“學習的過程就是不斷的發現錯誤,不斷的改正錯誤”;

先看下手冊上怎么說的吧!

對一般人來說看下前兩段就可以了

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().
這些英文實在是需要像我這類人有足夠的耐心啊(不是說我有耐心,而是我英語爛),剛才也說了,對于一般人只看下前兩段就可以了,特別是我用紅色標出來的字!!!

另外,特別注意的是,魔術引用發生作用是在傳遞$_GET,$_POST,$_COOKIE時

下面是案例

代碼:
1.
條件: magic_quotes_gpc=off
寫入數據庫的字符串未經過任何過濾處理。從數據庫讀出的字符串也未作任何處理。

數據:  $data="snow''''sun" ; (snow和sun之間是四個連續的單引號).

操作: 將字符串:"snow''''sun" 寫入數據庫,

結果: 出現sql語句錯誤,mysql不能順利完成sql語句,寫入數據庫失敗。

數據庫保存格式:無數據。

輸出數據格式:無數據。

說明: 對于未經處理的單引號在寫入數據庫時會使sql語句發生錯誤。

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

數據:  $data="snow''''sun" ; (snow和sun之間是四個連續的單引號).

操作: 將字符串:"snow''''sun" 寫入數據庫,

結果: sql語句順利執行,數據成功寫入數據庫

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

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

說明: addslashes()函數將單引號轉換為/'的轉義字符使sql語句成功執行,
但/'并未作為數據存入數據庫,數據庫保存的是snow''''sun 而并不是我們想象的snow/'/'/'/'sun

代碼:
3.
條件: magic_quotes_gpc=on
寫入數據庫的字符串未經過任何處理。從數據庫讀出的字符串未作任何處理。

數據:  $data="snow''''sun" ; (snow和sun之間是四個連續的單引號).

操作: 將字符串:"snow''''sun" 寫入數據庫,

結果: sql語句順利執行,數據成功寫入數據庫

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

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

說明: magic_quotes_gpc=on 將單引號轉換為/'的轉義字符使sql語句成功執行,
但/'并未作為數據入數據庫,數據庫保存的是snow''''sun而并不是我們想象的snow/'/'/'/'sun。

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

數據:  $data="snow''''sun" ; (snow和sun之間是四個連續的單引號).

操作: 將字符串:"snow''''sun" 寫入數據庫,

結果: sql語句順利執行,數據成功寫入數據庫

數據庫保存格式:snow/'/'/'/'sun (添加了轉義字符)

輸出數據格式:snow/'/'/'/'sun (添加了轉義字符)

說明: magic_quotes_gpc=on 將單引號轉換為/'的轉義字符使sql語句成功執行,
addslashes又將即將寫入數據庫的單引號轉換為/',后者的轉換被作為數據寫入
數據庫,數據庫保存的是snow/'/'/'/'sun
總結如下:

1. 對于magic_quotes_gpc=on的情況,

我們可以不對輸入和輸出數據庫的字符串數據作
addslashes()和stripslashes()的操作,數據也會正常顯示。

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

2. 對于magic_quotes_gpc=off 的情況

必須使用addslashes()對輸入數據進行處理,但并不需要使用stripslashes()格式化輸出
因為addslashes()并未將反斜杠一起寫入數據庫,只是幫助mysql完成了sql語句的執行。

補充:

magic_quotes_gpc 作用范圍是:WEB客戶服務端;作用時間:請求開始時,例如當腳本運行時.
magic_quotes_runtime 作用范圍:從文件中讀取的數據或執行exec()的結果或是從SQL查詢中得到的;作用時間:每次當腳本訪問運行狀態中產生的數據

php技術php magic_quotes_gpc的一點認識與分析,轉載需保留來源!

鄭重聲明:本文版權歸原作者所有,轉載文章僅為傳播更多信息之目的,如作者信息標記有誤,請第一時間聯系我們修改或刪除,多謝。

主站蜘蛛池模板: 国产精品久久人妻互换毛片 | 国产99视频精品免费播放 | 伊人yinren6综合网色狠狠 | 亚洲国产高清在线观看视频 | 日本枯瘦娇小 | 97国产成人精品免费视频 | 国产网红主播精品福利大秀专区 | 女子初尝黑人巨嗷嗷叫 | jizz丝袜 | 成在线人免费视频 | 无码任你躁久久久久久老妇双奶 | 国产a在线不卡 | 免费啪视频观试看视频 | 韩国免费啪啪漫画无遮拦健身教练 | 91嫩草视频在线观看 | 人妻无码AV中文系统久久免费 | 99免费在线观看视频 | 日韩高清特级特黄毛片 | 脱女学小内内摸出水网站免费 | 亚洲免费精品视频 | 欧美亚洲另类图片 | jizz国产丝袜18老师美女 | 好大好硬好湿再深一点网站 | 国产精品亚洲国产三区 | 暖暖在线观看播放视频 | 亚洲AV国产精品无码精 | 国产免费内射又粗又爽密桃视频 | 高h肉文合集 | 7723手机游戏破解版下载 | 午夜人妻理论片天堂影院 | 国产 精品 亚洲 欧美 高清 | 国产成人综合视频 | 特级做A爰片毛片免费69 | YY8090福利午夜理论片 | 99re1久久热在线播放 | 久久资源365 | 99久久免热在线观看 | 欧美狂野乱码一二三四区 | 亚洲精品视频免费看 | 国产精品久久免费视频 | 三级叫床震大尺度视频 |