原帖地址
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中報錯,寫入文件中運行時也出現問題,疑爲有所闕漏。