Another reason against it: security. You could be lulled in a feeling of false security if you have magic_quotes=On on a test server and Off on production server.
And another: readability of the code. If you want to be portable you need to resort to some weird solution, outlines on these pages (if (get_magic_quotes())...).
Let's hope magic_quotes soon goes to history together with safe_mode and similar "kind-of-security" (but in reality just a nuisance) inventions.
なぜマジッククオートを使用しないのか
警告
この機能は PHP 5.3.0 で 非推奨となり、PHP 6.0.0 で削除されます。 この機能を使用しないことを強く推奨します。
- 移植性 これがonであることを仮定すると、移植性に影響します。 この確認のためにget_magic_quotes_gpc()を 使用し、適切なコーディングを行ってください。
- 性能 エスケープされたデータが全てデータベースに挿入されるわけではないので、 このように全てのデータをエスケープすることは性能を低下させます。 単に(addslashes()のような)エスケープを行う関数を 実行時にコールする方がより効率的です。 php.ini-developmentはこれらのディレクティブを デフォルトで有効にしていますが、 php.ini-productionはこれを無効にしています。 この推奨は主に性能面によるものです。
- 不便 全てのデータをエスケープする必要はないため、しばしば、 エスケープするべきではないデータまでエスケープされてしまう問題に 悩まされることになります。例えば、フォームからメールを送信する際、 emailの中に多くの \' が含まれることになります。 これを修正するために、 stripslashes()を大量に使用することが必要と なる可能性があります。
なぜマジッククオートを使用しないのか
anze
14-Oct-2008 07:23
14-Oct-2008 07:23
estoesunapija at hotmail dot com
16-Sep-2008 02:26
16-Sep-2008 02:26
<?php
//One could use array_walk, altough i think it was fun
//and simple doing it this way.
class oop {
//toObject : Transforms an array into an object filtering it
//$source : Array to transform
//$currentLevel : See $maxLevels
//$maxLevels : Protect the system in case of lots of recursion
// i.e. <input type="text" name="test[][]....[N]"
public static function toObject($source=array(),$array=array(),$maxLevels=3,$currentLevel=0) {
if ( !sizeof($source) || ($currentLevel > $maxLevels) ) return FALSE;
$array = (sizeof($array)) ? $array : $source;
$obj = new stdClass();
foreach ($array as $k => $v){
if (is_array($v)) {
$obj->$k = self::toObject($source,$v,$maxLevels,++$currentLevel);
continue;
}
//Assign to the object $obj, the key and the value of the actual value of $source
$obj->$k=$v;
}
return $obj;
}
}
/* Eexamples
$post = oop::toObject($_POST) ;
$get = oop::toObject($_GET) ;
$session = oop::toObject($_SESSION);
var_dump ($post) ;
var_dump ($get) ;
var_dump ($session);
*/
?>
sir dot steve dot h+php at gmail dot com
07-Dec-2007 01:45
07-Dec-2007 01:45
I find it useful to define a simple utility function for magic quotes so the application functions as expected regardless of whether magic_quotes_gpc is on:
function strip_magic_slashes($str)
{
return get_magic_quotes_gpc() ? stripslashes($str) : $str;
}
Which can be annoying to add the first time you reference every $_GET /$_POST/$_COOKIE variable, but it prevents you from demanding your users to change their configurations.
rjh at netcraft dot com
13-Jun-2007 06:50
13-Jun-2007 06:50
Additionally, addslashes() is not a cure-all against SQL injection attacks. You should use your database's dedicated escape function (such as mysql_escape_string) or better yet, use parameterised queries through mysqli->prepare().
12-Feb-2006 06:47
It is also important to disable Magic Quotes while in development enivronment. For the reasons mentioned above, not everybody is using Magic Quotes.
An application that works fine with Magic Quotes enabled may have security problems (ie can be subject to SQL attacks) when distributed.
