Joomla错误:'非法变量_files或_env或_get或_post或_cookie或_server或_session或全局传递给脚本'

时间:2011-12-02 13:01:04

标签: php forms joomla

我在Joomla中收到此错误:

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

我没有太多帮助谷歌搜索。

4 个答案:

答案 0 :(得分:9)

如果您尝试指定名称仅由数字组成的URL参数,则会看到此错误,例如

http://www.example.com/?1234567=test

或者如果您尝试使用joomla-reserved变量,例如

http://www.example.com/?_files=test

这不是一个很好的错误消息。如果您可以访问unix终端,可以使用某些命令行工具调试这些问题,例如

$ find /var/www/html -exec grep -l 'Illegal variable' {} \;
/var/www/html/libraries/joomla/environment/request.php

这是一个虚构的joomla安装,假设一个相当标准的DocumentRoot。结果立即确认这是一个Joomla错误,并报告导致它的文件。从该文件中提取:

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 );

    // PHP Zend_Hash_Del_Key_Or_Index bug 
    $failed |= is_numeric( $key );

    if ($failed) {
        jexit( 'Illegal variable <b>' . implode( '</b> or <b>', $banned ) . '</b> passed to script.' );
    }
    ...
}

请注意,错误消息特别具有误导性,因为不仅在保留变量名称的情况下抛出,而且参数名称是数字。

答案 1 :(得分:4)

这不是PHP生成的错误,这是一个似乎属于Joomla的错误!在Google搜索“非法变量”20秒后,我发现this page

答案 2 :(得分:0)

我必须为joomla 1.5解决这个问题

我是这样做的

找到文件/ {your_joomla_folder} /libraries/joomla/environment/request.php

使错误更友好

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( '</b> or <b>', $banned );
            }
            throw new Exception( 'Illegal variable <b>' . $str . '</b> passed to script.'.(($is_injection)?' (globals injection)': ' key "'.$key.'" is numeric in '.$str) );
            //jexit( 'Illegal variable <b>' . implode( '</b> or <b>', $banned ) . '</b> passed to script.' );
        }
        if ($globalise) {
            $GLOBALS[$key] = $value;
        }
    }
}

在我的情况下,AJAX脚本将文件上传为

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

0导致了问题,所以因为这是一个最小的脚本,我可以简单地将信息从$_FILES传输到joomla加载之前的其他地方

例如:

$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';

请注意,在包含$files之后,您无法使用变量/includes/framework.php,因为joomla将无效地使用null覆盖

答案 3 :(得分:-1)

唯一有效的解决方案是在 request.php 文件中传递以下一行

找到文件/ {your_joomla_folder} /libraries/joomla/environment/request.php

// $ failed | = is_numeric($ key);