2013-02-07 40 views
-1

我想在PHP中關閉魔術引號,但無法禁用它 - 我在/usr/local/lib/php.ini中設置了下面的內容並重新啓動了Apache,但是它沒有任何區別。在PHP中關閉魔術引號似乎並不工作

; Magic quotes 

; Magic quotes for incoming GET/POST/Cookie data. 
magic_quotes_gpc = Off 

; Magic quotes for runtime-generated data, e.g. data from SQL, from exec(), etc. 
magic_quotes_runtime = Off 

; Use Sybase-style magic quotes (escape ' with '' instead of \'). 
magic_quotes_sybase = Off 

phpinfo確認這些都設置爲關閉。

magic_quotes_gpc Off Off 
magic_quotes_runtime Off Off 
magic_quotes_sybase Off Off 

然後我嘗試添加

php_flag magic_quotes_gpc off 

到htaccess,但給人的500內部服務器錯誤 - 在error_log中尋找有什麼加入到告訴我,爲什麼這可能發生。

服務器運行的Centos 5.8 64位與CPanel/WHM和前端是Wordpress與後臺自定義PHP應用程序。 PHP版本是5.3.18和加載配置文件是/usr/local/lib/php.ini

我認爲它不工作的原因是,下面的消息是從MySQL那裏得到的,它有mysql_real_escape_string,addslashes和在添加到數據庫之前,將htmlspecialchars應用於它。

原始消息是:

This is a "how to" question. I don't think it is covered in the notes - sorry if I've missed it. 

它被添加到MySQL作爲:

This is a "how to" question. I don\'t think it is covered in the notes - sorry if I\'ve missed it. 

當接着在屏幕上顯示它顯示爲:

This is a \\"how to\\" question. I don\\\'t think it is covered in the notes - sorry if I\\\'ve missed it. 

而當striplashes然後適用於此,它變成:

This is a \"how to\" question. I don\'t think it is covered in the notes - sorry if I\'ve missed it. 

我在做什麼錯,或者我可以嘗試什麼?

+0

哪個PHP版本? – 0wn3r

+0

我不是這方面的專家,但我懷疑它可能對你的問題中的一個例子很有用,那就是你爲什麼認爲它不工作,即告訴我們PHP在做什麼,你想要它不要做。 – MadHatter

+1

我建議創建一個包含「<?php phpinfo()」的小測試PHP文件;「首先會顯示是否正在讀取ini文件,該ini文件的路徑以及上述設置的當前值。 –

回答

0

\&quot;不是魔術引號或addslashes()的結果。

另外,我想不出一個標準的PHP引用函數,它將用\&quot;替換雙引號,並用斜槓轉義單引號。你的代碼有更深的錯誤。

+0

htmlspecialchars更改爲「" – bhttoan

+0

是的,但它不會使用反斜槓單引號。我的觀點是沒有一個函數可以同時執行這兩個操作。 – longneck

+0

我已將更多信息添加到原始郵件中以顯示我在每個階段看到的輸出 – bhttoan