Ошибка PHP в директиве register_globals
![]()  | 
		Недавно обновил язык PHP до php5-5.3.2. В логе web-сервера apache-2.0.63_3 появились такие ошибки:
Warning: Directive 'register_globals' is deprecated in PHP 5.3 and greater in Unknown on line 0 PHP Warning: Directive 'register_globals' is deprecated in PHP 5.3 and greater in Unknown on line 0  | 
		
На сервере PHP Manual есть предупреждение о том, что в будущих версиях php6.x.x использование директивы register_globals будет прекращено.
Warning. This feature has been DEPRECATED as of PHP 5.3.0 and REMOVED as of PHP 6.0.0. Relying on this feature is highly discouraged.
Сам я пока не программирую на языке php, для меня важно только избавиться от этих ошибок. Для этого необходимо в файле настройки языка PHP5, расположенного по пути /usr/local/etc/php.ini, закомментировать строки с упоминанием директивы register_globals:
# nano -w /usr/local/etc/php.ini ; You should do your best to write your scripts so that they do not require ; register_globals to be on; Using form variables as globals can easily lead ; to possible security problems, if the code is not very well thought of. ;register_globals = Off ;register_globals = On
Для тех, кто программирует на языке php, разработчики предлагают вот такие варианты решения проблемы с использованием этой директивы в дальнейшем:
This will emulate register_globals On. If you altered your variables_order directive, consider 
changing the $superglobals accordingly.
<?php
// Emulate register_globals on
if (!ini_get('register_globals')) {
    $superglobals = array($_SERVER, $_ENV,
        $_FILES, $_COOKIE, $_POST, $_GET);
    if (isset($_SESSION)) {
        array_unshift($superglobals, $_SESSION);
    }
    foreach ($superglobals as $superglobal) {
        extract($superglobal, EXTR_SKIP);
    }
}
?>
This will emulate register_globals Off. Keep in mind, that this code should be called at the very 
beginning of your script, or after session_start() if you use it to start your session.
<?php
// Emulate register_globals off
function unregister_GLOBALS()
{
    if (!ini_get('register_globals')) {
        return;
    }
    // Might want to change this perhaps to a nicer error
    if (isset($_REQUEST['GLOBALS']) || isset($_FILES['GLOBALS'])) {
        die('GLOBALS overwrite attempt detected');
    }
    // Variables that shouldn't be unset
    $noUnset = array('GLOBALS',  '_GET',
                     '_POST',    '_COOKIE',
                     '_REQUEST', '_SERVER',
                     '_ENV',     '_FILES');
    $input = array_merge($_GET,    $_POST,
                         $_COOKIE, $_SERVER,
                         $_ENV,    $_FILES,
                         isset($_SESSION) && is_array($_SESSION) ? $_SESSION : array());
    foreach ($input as $k => $v) {
        if (!in_array($k, $noUnset) && isset($GLOBALS[$k])) {
            unset($GLOBALS[$k]);
        }
    }
}
unregister_GLOBALS();
?>
 
    
    
  








