Joomla error: 'Illegal variable _files or _env or _get or _post or _cookie or _server or _session or globals passed to script'

后端 未结 4 366
逝去的感伤
逝去的感伤 2021-01-21 17:57

I am getting this error in Joomla:

Illegal variable `_files` or `_env` or `_get` or `_post` or `_cookie`
or `_server` or `_session` or `globals` passed to script         


        
4条回答
  •  北恋
    北恋 (楼主)
    2021-01-21 18:41

    I had to fix this for joomla 1.5

    Here is how I did it

    Find the file /{your_joomla_folder}/libraries/joomla/environment/request.php

    And make the error friendlier

    function clean()
    {
        JRequest::_cleanArray( $_FILES , false, 'FILES');
        JRequest::_cleanArray( $_ENV , false, 'ENV' );
        JRequest::_cleanArray( $_GET , false, 'GET' );
        JRequest::_cleanArray( $_POST , false, 'POST' );
        JRequest::_cleanArray( $_COOKIE , false, 'COOKIE' );
        JRequest::_cleanArray( $_SERVER , false, 'SERVER' );
    
        if (isset( $_SESSION )) {
            JRequest::_cleanArray( $_SESSION , false, 'SESSION' );
        }
    
        $REQUEST    = $_REQUEST;
        $GET        = $_GET;
        $POST       = $_POST;
        $COOKIE     = $_COOKIE;
        $FILES      = $_FILES;
        $ENV        = $_ENV;
        $SERVER     = $_SERVER;
    
        if (isset ( $_SESSION )) {
            $SESSION = $_SESSION;
        }
    
        foreach ($GLOBALS as $key => $value)
        {
            if ( $key != 'GLOBALS' ) {
                unset ( $GLOBALS [ $key ] );
            }
        }
        $_REQUEST   = $REQUEST;
        $_GET       = $GET;
        $_POST      = $POST;
        $_COOKIE    = $COOKIE;
        $_FILES     = $FILES;
        $_ENV       = $ENV;
        $_SERVER    = $SERVER;
    
        if (isset ( $SESSION )) {
            $_SESSION = $SESSION;
        }
    
        // Make sure the request hash is clean on file inclusion
        $GLOBALS['_JREQUEST'] = array();
    }
    function _cleanArray( &$array, $globalise=false, $type=null )
    {
        static $banned = array( '_files', '_env', '_get', '_post', '_cookie', '_server', '_session', 'globals' );
    
        foreach ($array as $key => $value)
        {
            // PHP GLOBALS injection bug
            $failed = in_array( strtolower( $key ), $banned );
            $is_injection = false;
            if($failed){
                $is_injection = true;
            }
    
            // PHP Zend_Hash_Del_Key_Or_Index bug
            $failed |= is_numeric( $key );
            if ($failed) {
                if($type){
                    $str = $type;
                }else{
                    $str = implode( ' or ', $banned );
                }
                throw new Exception( 'Illegal variable ' . $str . ' passed to script.'.(($is_injection)?' (globals injection)': ' key "'.$key.'" is numeric in '.$str) );
                //jexit( 'Illegal variable ' . implode( ' or ', $banned ) . ' passed to script.' );
            }
            if ($globalise) {
                $GLOBALS[$key] = $value;
            }
        }
    }
    

    In my case an AJAX script was uploading files as

    $_FILES = array(
        0=>array(
            [name] => 6767.bmp
        [type] => image/bmp
        [tmp_name] => /tmp/phpfbIzXU
        [error] => 0
        [size] => 12774
        ),
    );
    

    The 0 was causing problems, so because this was a minimal script I could simply transfer the info from $_FILES to somewhere else before joomla loaded

    for example like this:

    $files = array();
    foreach($_FILES as $f){
        $files[] = $f;
    }
    $_FILES = array('files'=>$files);
    
    ... joomla launch code...
    define( '_JEXEC', 1 );
    define('JPATH_BASE', realpath(dirname(dirname(__FILE__).'/')));
    define( 'DS', DIRECTORY_SEPARATOR );
    require JPATH_BASE . DS . 'includes' . DS . 'defines.php';
    require JPATH_BASE . DS . 'includes' . DS . 'framework.php';
    

    Note that you can't use the variable $files after including /includes/framework.php as joomla will unhelpfully overwrite it with null

提交回复
热议问题