|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2002-06-14 03:23 UTC] php dot net at odi dot ch
magic_quotes_gpc is a bad idea and should be abandoned for the following reasons: While the option may look very tempting at the first glance there are some caveats however: 1. Most parameters do not go to a database. In a web application most form field are used internally without the need to store them in a database. Magic quotes cause troubles in these cases. Moreover the data passed to the application is not the data entered by the user if it was processed by magic quotes. This is undesireable. 2. Impedes code reuse. If you feed data from either form parameters or internal data sources into the same function then your function must know if the data was processed by magic quotes or not. 3. Bad surprises at deployment time and code portability. If you do not carefully check if this parameter is set on your development and production system you can run into troubles. Especially if you can not change the settings on one system (because the hoster does not let you). 4. Behaviour can not be controlled at script runtime. The ini_set does not help in this case. Even though the parameter can be modified at runtime the behaviour does not change. Consequently you are bound to the php.ini settings (which may be not under the developer's control). I therefore request that this (and related) option be removed from future versions of PHP and the default behaviour should be FALSE. PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Dec 17 00:00:02 2025 UTC |
I really don't get the 'poor-quality' statement. The feature protects the weak and unwary against sql injection and it's easy to work around it, using get_magic_quotes_gpc(). All you're asking for, is not having to verify client-sent data, which IMO is poor quality to begin with and link that to code-reuse and deployment problems. The problem is with your assumptions - not the feature. Example: <?php // This function should be called whenever some variable is directly inserted // into the database, when coming from $_REQUEST (and of course it's partials // $_GET, $_POST etc.). function safe_addslashes($string) { // Using a static variable, speeds up multiple calls. static $setting=-1; if($setting === -1) { $setting = get_magic_quotes_gpc(); } return ($setting) ? $string : addslashes($string); } // This function should be called whenever some variable is directly output // to the browser or a datasource that is not affected by quotes, when coming // from $_REQUEST (and of course it's partials $_GET, $_POST etc.). function safe_stripslashes($string) { static $setting = -1; if($setting === -1) { $setting = get_magic_quotes_gpc(); } return ($setting) ? stripslashes($string) : $string; } ?>