вторник, 4 ноября 2008 г.

PHP. Magic quotes.

Problem: PHP processed all input (GET, POST, COOKIE) and all quotes found there were automatically escaped.

Solution:

1) turn off magic_quotes_gpc in php.ini.

2)

<?php
if (get_magic_quotes_gpc()) {
    function strip_quotes(&$var) {
        if (is_array($var) {
            array_walk($var, 'strip_quotes');
        } else {
            $var = stripslashes($var);
        }
    }

    // Handle GPC
        foreach (array('GET','POST','COOKIE') as $v) {
            if (!empty(${"_".$v})) {
                array_walk(${"_".$v}, 'strip_quotes');
            }
        }
}
?>

Комментариев нет: