
Immediately it is worth noting that with the release of php 6, this article will not be relevant, but for now ...
Anyone who has experience working with php surely knows or has heard of the magic_quotes_gpc directive (magic quotes). If the directive flag is set to “On”, then the data transmitted in the $ _GET, $ _POST, $ _COOKIE arrays is automatically escaped (which is what hints gpc at the end of the directive).
When developing a site on the Zend Framework, one of the requirements is disabled "magic_quotes_gpc". The thing is that the Zend Framework itself shields the data and with the magic_quotes_gpc directive turned on, double shielding is obtained, which is not good and beautiful.
The problem would not be so acute if all the hosting companies gave the right to change the value of "magic_quotes_gpc" . I have already faced such a problem more than once and found in my opinion a rather elegant solution.
')
In the case when the server directive "magic_quotes_gpc" is strictly set to "On" we will connect a small plugin to avoid double shielding:
/**
* .
*
* , magic_quotes_gpc.
*
* @category Zend_Controller_Plugin
*/
class Singular_Controller_Plugin_StripMagicQuotes extends Zend_Controller_Plugin_Abstract
{
/**
* , Zend_Controller_Front .
*
* @param Zend_Controller_Request_Abstract $request
* @return void
*/
public function dispatchLoopStartup(Zend_Controller_Request_Abstract $request)
{
/** magic_quotes_gpc */
if (get_magic_quotes_gpc()) {
/** */
$ params = $request->getParams();
/** "exStripSlashes" */
array_walk_recursive($ params , array($ this , 'exStripSlashes' ));
/** */
$request->setParams($ params );
}
}
/**
* .
*
* @param mixed $value
* @param mixed $key
* @return void
*/
private function exStripSlashes(&$ value , $key)
{
/** */
$ value = stripslashes($ value );
}
}
* This source code was highlighted with Source Code Highlighter .
Do not forget to rename the class name according to
the framework convention and register the plugin:
/** - */
$front = Zend_Controller_Front::getInstance();
/** */
$front->registerPlugin( new Singular_Controller_Plugin_StripMagicQuotes());
* This source code was highlighted with Source Code Highlighter .
Thank you for your attention, have a nice day.