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
> HTTPd, Revp. COOKIE). Cannot be set at runtime, and defaults to on in PHP.
magic_quotes_runtime
代碼:
If enabled, most functions that return data from an exso source, avecom sources, files and sources, files. 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 inf cet 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. Magicml.
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 Why not to use Magic Quotes
1 Portability
代碼:
Assuming 1 Portability
代碼:
Assuming it to be on, itor portability. Use get_magic_quotes_gpc() to check for this, and code accordingly.
2 Performance
程式碼:
Because not every piece of escaped data 程式碼:
Because not every piece of escaped data is incess ins insject insoo is集, is insoo, sis insly sis ins sis ins在內, s鍛煉s insly shis insly s通常s sis ins sis ins N通常s s錯誤, s通常s sis ins sis ins sis ins s錯誤, s立面s ins sis ins略 is sis ins is insis ins s在內包括表 集, is insoo inties soo. 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-commended disables these directives by default, php.ini-commended disables these directives by default, php.ini-commended sablesue commended sables. reasons.
3 Inconvenience
代碼:
Because not all data needs escaping, it's often annoying to see escaped data where it shouldn't be. Forample, email exing and e be. For 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查詢中得到的;作用時間:每次當腳本存取執行狀態中產生的數據
以上就介紹了quotes php magic_quotes_gpc的一點認識與分析,包括了quotes方面的內容,希望對PHP教程有興趣的朋友有所幫助。

phpsessionstrackuserdataacrossmultiplepagerequestsusingauniqueIdStoredInAcookie.here'showtomanageThemeffectionaly:1)startAsessionWithSessionWwithSession_start()和stordoredAtain $ _session.2)

在PHP中,遍歷會話數據可以通過以下步驟實現:1.使用session_start()啟動會話。 2.通過foreach循環遍歷$_SESSION數組中的所有鍵值對。 3.處理複雜數據結構時,使用is_array()或is_object()函數,並用print_r()輸出詳細信息。 4.優化遍歷時,可採用分頁處理,避免一次性處理大量數據。這將幫助你在實際項目中更有效地管理和使用PHP會話數據。

會話通過服務器端的狀態管理機制實現用戶認證。 1)會話創建並生成唯一ID,2)ID通過cookies傳遞,3)服務器存儲並通過ID訪問會話數據,4)實現用戶認證和狀態管理,提升應用安全性和用戶體驗。

Tostoreauser'snameinaPHPsession,startthesessionwithsession_start(),thenassignthenameto$_SESSION['username'].1)Usesession_start()toinitializethesession.2)Assigntheuser'snameto$_SESSION['username'].Thisallowsyoutoaccessthenameacrossmultiplepages,enhanc

PHPSession失效的原因包括配置錯誤、Cookie問題和Session過期。 1.配置錯誤:檢查並設置正確的session.save_path。 2.Cookie問題:確保Cookie設置正確。 3.Session過期:調整session.gc_maxlifetime值以延長會話時間。

在PHP中調試會話問題的方法包括:1.檢查會話是否正確啟動;2.驗證會話ID的傳遞;3.檢查會話數據的存儲和讀取;4.查看服務器配置。通過輸出會話ID和數據、查看會話文件內容等方法,可以有效診斷和解決會話相關的問題。

多次調用session_start()會導致警告信息和可能的數據覆蓋。 1)PHP會發出警告,提示session已啟動。 2)可能導致session數據意外覆蓋。 3)使用session_status()檢查session狀態,避免重複調用。

在PHP中配置會話生命週期可以通過設置session.gc_maxlifetime和session.cookie_lifetime來實現。 1)session.gc_maxlifetime控制服務器端會話數據的存活時間,2)session.cookie_lifetime控制客戶端cookie的生命週期,設置為0時cookie在瀏覽器關閉時過期。


熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

Video Face Swap
使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱門文章

熱工具

記事本++7.3.1
好用且免費的程式碼編輯器

SAP NetWeaver Server Adapter for Eclipse
將Eclipse與SAP NetWeaver應用伺服器整合。

ZendStudio 13.5.1 Mac
強大的PHP整合開發環境

MantisBT
Mantis是一個易於部署的基於Web的缺陷追蹤工具,用於幫助產品缺陷追蹤。它需要PHP、MySQL和一個Web伺服器。請查看我們的演示和託管服務。

PhpStorm Mac 版本
最新(2018.2.1 )專業的PHP整合開發工具