How can PHP magic_quotes affect the functionality of a script?

PHP magic_quotes can add slashes to incoming data, which can cause issues with certain functions like database queries or file operations. To solve this issue, you can use the stripslashes() function to remove the added slashes before using the data in your script.

if (get_magic_quotes_gpc()) {
    $input = array(&$_GET, &$_POST, &$_COOKIE, &$_REQUEST);
    while (list($k, $v) = each($input)) {
        foreach ($v as $key => $val) {
            if (!is_array($val)) {
                $input[$k][$key] = stripslashes($val);
                continue;
            }
            $input[] = &$input[$k][$key];
        }
    }
    unset($input);
}