How can the use of magic_quotes_gpc impact the security and functionality of a PHP script?

The use of magic_quotes_gpc in PHP can impact security by automatically escaping characters in user input, potentially leading to double escaping and SQL injection vulnerabilities. It can also affect functionality by altering the input data and causing unexpected behavior in the script. To address this issue, it is recommended to disable magic_quotes_gpc and handle input validation and sanitization manually.

// Disable magic_quotes_gpc
if (get_magic_quotes_gpc()) {
    function stripslashes_deep($value) {
        $value = is_array($value) ? array_map('stripslashes_deep', $value) : stripslashes($value);
        return $value;
    }
    $_POST = array_map('stripslashes_deep', $_POST);
    $_GET = array_map('stripslashes_deep', $_GET);
    $_COOKIE = array_map('stripslashes_deep', $_COOKIE);
    $_REQUEST = array_map('stripslashes_deep', $_REQUEST);
}