原帖地址
PHP5.4是公开发行的PHP程式最新版本。其执行速度和内存占用等相比PHP5.3而言有10%~30%的性能提升,所以笔者也一直想在实际环境中试运行PHP5.4(PHP5.4目前最新的版本为5.4.9)。
棘手的是与PHP5.2升级到PHP5.3有所不同的是,从5.3到5.4之间似乎变化不少,这也造成了笔者在将DEDECMS系统迁移到PHP5.4.x平台的时候出现了前台500错误后台直接空白的情况,当时也没有深究便换回PHP5.3了。
最近仔细查了下相关资料,发现主要是因为目前DEDECMS代码中使用了PHP5.4中弃用的一些函数,主要如下:
allow_call_time_pass_reference、define_syslog_variables、highlight.bg、register_globals、register_long_arrays、magic_quotes、safe_mode、zend.ze1_compatibility_mode、session.bug_compat42、session.bug_compat_warn、session_register以及 y2k_compliance等。
其中造成DEDECMS5.7无法正常运行的函数便是session_register。
网上实测有效的方法有两种。
第一种是申明将此函数废弃,在include/userlogin.class.php中加入如下代码:
1 | function session_register() |
第二种方法是该该页中的函数代码替换,被替换代码大致在287到308行之间:
01 | @session_register( $this ->keepUserIDTag); |
02 | $_SESSION [ $this ->keepUserIDTag] = $this ->userID; |
03 | @session_register( $this ->keepUserTypeTag); |
04 | $_SESSION [ $this ->keepUserTypeTag] = $this ->userType; |
05 | @session_register( $this ->keepUserChannelTag); |
06 | $_SESSION [ $this ->keepUserChannelTag] = $this ->userChannel; |
07 | @session_register( $this ->keepUserNameTag); |
08 | $_SESSION [ $this ->keepUserNameTag] = $this ->userName; |
09 | @session_register( $this ->keepUserPurviewTag); |
10 | $_SESSION [ $this ->keepUserPurviewTag] = $this ->userPurview; |
11 | @session_register( $this ->keepAdminStyleTag); |
12 | $_SESSION [ $this ->keepAdminStyleTag] = $adminstyle ; |
13 | PutCookie(‘DedeUserID’, $this ->userID, 3600 * 24, ‘/’); |
14 | PutCookie(‘DedeLoginTime’, time(), 3600 * 24, ‘/’); |
替换为:
01 | global $admincachefile , $adminstyle ; |
02 | if ( empty ( $adminstyle )) $adminstyle = ‘dedecms’; |
03 | $_SESSION [ $this ->keepUserIDTag] = $this ->keepUserIDTag; |
04 | $_SESSION [ $this ->keepUserIDTag] = $this ->userID; |
05 | $_SESSION [ $this ->keepUserTypeTag] = $this ->keepUserTypeTag; |
06 | $_SESSION [ $this ->keepUserTypeTag] = $this ->userType; |
07 | $_SESSION [ $this ->keepUserChannelTag] = $this ->keepUserChannelTag; |
08 | $_SESSION [ $this ->keepUserChannelTag] = $this ->userChannel; |
09 | $_SESSION [ $this ->keepUserNameTag] = $this ->keepUserNameTag; |
10 | $_SESSION [ $this ->keepUserNameTag] = $this ->userName; |
11 | $_SESSION [ $this ->keepUserPurviewTag] = $this ->keepUserPurviewTag; |
12 | $_SESSION [ $this ->keepUserPurviewTag] = $this ->userPurview; |
13 | $_SESSION [ $this ->keepAdminStyleTag] = $this ->keepAdminStyleTag; |
14 | $_SESSION [ $this ->keepAdminStyleTag] = $adminstyle ; |
15 | PutCookie(‘DedeUserID’, $this ->userID, 3600 * 24, ‘/’); |
16 | PutCookie(‘DedeLoginTime’, time(), 3600 * 24, ‘/’); |
两种方法的本质第一种一是直接弃用函数,简单暴力,但是有安全隐患,第二种是更改为新函数,较为妥当。实测均能使DEDECMS正常运行。
另外DEDECMS论坛中版主吕轻侯给出的方法是在/include/helpers/util.helper.php页中插入如下代码:
02 | function fix_session_register(){ |
03 | function session_register(){ |
04 | $args = func_get_args(); |
05 | foreach ( $args as $key ){ |
06 | $_SESSION [ $key ]= $GLOBALS [ $key ]; |
09 | function session_is_registered( $key ){ |
10 | return isset( $_SESSION [ $key ]); |
12 | function session_unregister( $key ){ |
13 | unset( $_SESSION [ $key ]); |
16 | if (!function_exists( 'session_register' )) fix_session_register(); |
经过笔者测试,吕轻侯的代码段在DM中报错,写入文件中运行时也出现问题,疑为有所阙漏。