Zend Framework and magic quotes

Zend <a href= Framework & Magic Quotes">it is worth noting that with the release of php 6 this article is not relevant, and yet...

Anyone who has experience with php, probably knows or has heard about the Directive "magic_quotes_gpc"(magic quotes). If flag Directive is set to "On", the automatic escaping of data passed in the $_GET, $_POST, $_COOKIE(and hints abbreviation gpc at the end of directives).

When designing a website on Zend Framework e one of the requirements is off "magic_quotes_gpc". The thing is that Zend Framework itself screens the data and when the Directive "magic_quotes_gpc" is double-escaped, which is not good and beautiful. Problem would not be so acute if all hosts were given the right to change the value of "magic_quotes_gpc". I have repeatedly encountered this problem and found in my opinion a quite elegant solution.



In that case, when the server Directive "magic_quotes_gpc" is strictly set to "On", we will connect the small plug to avoid double-escaping:

/**
* the Plugin removes the shielding.
*
* Used in cases when the server is prohibited to turn off magic_quotes_gpc.
*
* @category Zend_Controller_Plugin
*/
class Singular_Controller_Plugin_Stripmagicquotes extends Zend_Controller_Plugin_Abstract
{
/**
* Called before Zend_Controller_Front enters a dispatch loop.
*
* @param Zend_Controller_Request_Abstract $request
* @return void
*/
public function dispatchLoopStartup(Zend_Controller_Request_Abstract $request)
{
/** included Check if the magic_quotes_gpc Directive */
if (get_magic_quotes_gpc()) {
/** Fetch the parameters */
$params = $request->getParams();
/** Recursively use the method of "exStripSlashes" to each element of the array */
array_walk_recursive($params, array($this 'exStripSlashes'));
/** Set the processed options */
$request- > setParams($params);
}
}

/**
* Removes the escaping characters.
*
* @param mixed $value
* @param mixed $key
* @return void
*/
private function exStripSlashes(&$value, $key)
{
/** Remove the escaping characters */
$value = stripslashes($value);
}
}


* This source code was highlighted with Source Code Highlighter.


Don't forget to rename the class name according to Convention framework and register a plugin:
/** Get the instance of the front controller */
$front = Zend_Controller_Front::getInstance();
/** Register the plugin */
$front- > registerPlugin(new Singular_Controller_Plugin_Stripmagicquotes());


* This source code was highlighted with Source Code Highlighter.


Thank you for your attention, have a good day.
Article based on information from habrahabr.ru

Комментарии

Популярные сообщения из этого блога

When the basin is small, or it's time to choose VPS server

Performance comparison of hierarchical models, Django and PostgreSQL

From Tomsk to Silicon Valley and Back