4月 24th, 2009

php4和php5的兼容问题

Category: php, Author: admin, Popularity: 24%

目前大多数php的open source都是用php4写的,在php5以上版本中,$HTTP_GET_VARS和$HTTP_POST_VARS等变量将无法使用,会出现一些莫名其妙的问题。下面的代码可以很好的解决这个问题

$ver_str = phpversion();
list($php_major, $php_minor, $php_sub) = explode( “.”, $ver_str);

if( intval($php_major) >= 5) {

$reg_long_arrays = ini_get(‘register_long_arrays’);

if( $reg_long_arrays == 0 ) {

if( !isset( $HTTP_SERVER_VARS ) )
$HTTP_SERVER_VARS =& $_SERVER;

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 =& $_COOKIES;

if( !isset( $HTTP_POST_FILES ) )
$HTTP_POST_FILES =& $_FILES;

if( !isset( $HTTP_ENV_VARS ) )
$HTTP_ENV_VARS =& $_ENV;

if( !isset( $HTTP_SESSION_VARS ) )
$HTTP_SESSION_VARS =& $_SESSION;
}

unset($reg_long_arrays);
}

unset($ver_str,$php_major,$php_minor,$php_sub);

另外一个不需要修改代码的解决办法:
php5不再默认支持$HTTP_POST_VARS[]和$HTTP_GET_VARS[],而改用$_POST[]和$_GET[]方式。如需要使用预定义数组,可以修改配置文件

php.ini:
register_long_arrays = Off
改为
register_long_arrays = On

热门日志

Tags:, .
评论数量() | Add Comments
本文网址:http://www.9usb.net/200904/php5-http_get_vars.html

There are No comments.

» You can leave a response

leave a reply