register_globals erro no php

2

Eu estava preso com o erro

directive 'register_globals' is no longer available in PHP in unknown on line 0

quando tentou verificar a versão do php usando "php -v" depois de ativar register_globals no arquivo php.ini. Eu não estou recebendo nenhuma informação sobre a versão php fazendo isso. Em vez disso, lança o erro acima mencionado.Depois de desligar esta opção, o php info funciona muito bem. É muito essencial que eu tenha register_globals para ser ativado. Como posso corrigir isso?

meu php.ini é o seguinte:

; Default Value: None
; Development Value: "GP"
; Production Value: "GP"
; http://php.net/request-order
request_order = "GP"

; Whether or not to register the EGPCS variables as global variables.  You may
; want to turn this off if you don't want to clutter your scripts' global scope
; with user data.
; 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 = On

; Determines whether the deprecated long $HTTP_*_VARS type predefined variables
; are registered by PHP or not. As they are deprecated, we obviously don't
; recommend you use them. They are on by default for compatibility reasons but
; they are not recommended on production servers.
; Default Value: On
; Development Value: Off
; Production Value: Off
; 
register_long_arrays = Off

; This directive determines whether PHP registers $argv & $argc each time it
; runs. $argv contains an array of all the arguments passed to PHP when a script
; is invoked. $argc contains an integer representing the number of arguments
; that were passed when the script was invoked. These arrays are extremely
; useful when running scripts from the command line. When this directive is
; enabled, registering these variables consumes CPU cycles and memory each time
; a script is executed. For performance reasons, this feature should be disabled
; on production servers.
; Note: This directive is hardcoded to On for the CLI SAPI
; Default Value: On
; Development Value: Off
; Production Value: Off
;
register_argc_argv = Off

; When enabled, the SERVER and ENV variables are created when they're first
; used (Just In Time) instead of when the script starts. If these variables
; are not used within a script, having this directive on will result in a
; performance gain. The PHP directives register_globals, register_long_arrays,
; and register_argc_argv must be disabled for this directive to have any affect.
;
auto_globals_jit = On
    
por user145862 16.11.2012 / 20:22

2 respostas

9

Na documentação :

This feature has been DEPRECATED as of PHP 5.3.0 and REMOVED as of PHP 5.4.0.

Você pode fazer o downgrade do PHP, ou remover register_globals do seu arquivo php.ini e consertar qualquer código que se refira a ele. Este último é preferível.

    
por 16.11.2012 / 20:26
1

A diretiva register_gobals foi DEPRECADA no PHP 5.3.0 e REMOVIDA a partir do PHP 5.4. 0 (por uma boa razão: pode facilmente levar a falhas de segurança se você não criar um código de alta qualidade)

Você não pode ativar a opção register_gobals no PHP 5.4 mais. Então, se você realmente precisa ter todas as variáveis registradas globais em alguns scripts, você precisa simular o comportamento antigo:

Crie o script php5.4-workaround.inc.php

<?php
// workaround for register_globals PHP 5.4:

/**
 * function to emulate the register_globals setting in PHP
 * for all of those diehard fans of possibly harmful PHP settings :-)
 * @author Ruquay K Calloway
 * @param string $order order in which to register the globals, e.g. 'egpcs' for default
 */
function register_globals($order = 'egpcs')
{
    // define a subroutine
    if(!function_exists('register_global_array'))
    {
        function register_global_array(array $superglobal)
        {
            foreach($superglobal as $varname => $value)
            {
                global $$varname;
                $$varname = $value;
            }
        }
    }

    $order = explode("\r\n", trim(chunk_split($order, 1)));
    foreach($order as $k)
    {
        switch(strtolower($k))
        {
            case 'e':    register_global_array($_ENV);        break;
            case 'g':    register_global_array($_GET);        break;
            case 'p':    register_global_array($_POST);        break;
            case 'c':    register_global_array($_COOKIE);    break;
            case 's':    register_global_array($_SERVER);    break;
        }
    }
}
register_globals();
?>

Em debians php.ini , o include_path contém /usr/share/php , portanto, se você colocar seu script lá, poderá incluí-lo em todos os scripts necessários:

<?php include("/usr/share/php/php5.4-workaround.inc.php"); ?>
    
por 20.10.2013 / 02:28

Tags