Reintroduce $HTTP_POST_VARS in PHP 5.3

后端 未结 4 1577
生来不讨喜
生来不讨喜 2020-12-09 05:31

I need to run a legacy PHP application in a shared hosting environment. I have promised my customer I\'ll support that legacy application for some time but I found that it d

相关标签:
4条回答
  • 2020-12-09 05:47

    You can do this

    config.php

    $HTTP_POST_VARS = &$_POST;
    $HTTP_GET_VARS = &$_GET;
    $HTTP_COOKIE_VARS = &$_COOKIE;
    

    .htaccess

    php_value auto_prepend_file /path/to/config.php
    

    PHP doc auto_prepend_file string

    Specifies the name of a file that is automatically parsed before the main file. The file is included as if it was called with the require function, so include_path is used.

    The special value none disables auto-prepending.

    EDIT: To be extra thorough, these are the other superglobals that could also be aliased:

    $HTTP_SERVER_VARS = &$_SERVER;
    $HTTP_POST_FILES = &$_FILES;
    $HTTP_SESSION_VARS = &$_SESSION;
    $HTTP_ENV_VARS = &$_ENV;
    
    0 讨论(0)
  • 2020-12-09 05:51

    register_long_arrays works for 5.3, but they nuked this in php 5.4

    http://www.php.net/manual/en/ini.core.php#ini.register-long-arrays

    And yes, this setting is labled PHP_INI_PERDIR, so you can set it via individual .htaccess or individual ini files, as well as set it globally.

    0 讨论(0)
  • 2020-12-09 06:02

    How about something like

    $HTTP_POST_VARS = $_POST;
    

    If you can include the code in the pages, that should work. Of course you have to have access to the source code and recompile the exe in windows, but you said could.

    0 讨论(0)
  • 2020-12-09 06:10

    It looks like the following can work.

    First, create an edisplaypatch.php somewhere with following code

    <?php
    
    if (getenv('EDISPLAY_PATCH')) {
        if (!isset($HTTP_GET_VARS)) $HTTP_GET_VARS = $_GET;
        if (!isset($HTTP_POST_VARS)) $HTTP_POST_VARS = $_POST;
        if (!isset($HTTP_COOKIE_VARS)) $HTTP_COOKIE_VARS = $_COOKIE;
    }
    
    ?>
    

    This code can be generalized and reused with any other program requiring the old long arrays

    Then in Apache's vhost configuration add

    SetEnv EDISPLAY_PATCH true
    

    Reload Apache.

    Test code works: if SetEnv is not present doesn't show nothing, if present shows what you send as rnd parameter in querystring

    <?php
    echo $HTTP_GET_VARS['rnd'];
    //phpinfo();
    ?>
    

    Little drawback: I'm including a file on EVERY PHP request

    0 讨论(0)
提交回复
热议问题