DEDECMS在PHP5.4不能正常运行的解决方法

本文实例讲述了DEDECMS在PHP5.4不能正常运行的解决方法。分享给大家供大家参考。具体分析如下:   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中加入如下代码:   代码如下:function session_register() { return true; } 第二种方法是该该页中的函数代码替换,被替换代码大致在287到308行之间,代码如下:   代码如下:@session_register($this->keepUserIDTag); $_SESSION[$this->keepUserIDTag] = $this->userID; @session_register($this->keepUserTypeTag); $_SESSION[$this->keepUserTypeTag] = $this->userType; @session_register($this->keepUserChannelTag); $_SESSION[$this->keepUserChannelTag] = $this->userChannel; @session_register($this->keepUserNameTag); $_SESSION[$this->keepUserNameTag] = $this->userName; @session_register($this->keepUserPurviewTag); $_SESSION[$this->keepUserPurviewTag] = $this->userPurview; @session_register($this->keepAdminStyleTag); $_SESSION[$this->keepAdminStyleTag] = $adminstyle; PutCookie('DedeUserID', $this->userID, 3600 * 24, '/'); PutCookie('DedeLoginTime', time(), 3600 * 24, '/'); 替换为如下代码:   代码如下:global $admincachefile,$adminstyle; if(emptyempty($adminstyle)) $adminstyle = 'dedecms'; $_SESSION[$this->keepUserIDTag] = $this->keepUserIDTag; $_SESSION[$this->keepUserIDTag] = $this->userID; $_SESSION[$this->keepUserTypeTag] = $this->keepUserTypeTag; $_SESSION[$this->keepUserTypeTag] = $this->userType; $_SESSION[$this->keepUserChannelTag] = $this->keepUserChannelTag; $_SESSION[$this->keepUserChannelTag] = $this->userChannel; $_SESSION[$this->keepUserNameTag] = $this->keepUserNameTag; $_SESSION[$this->keepUserNameTag] = $this->userName; $_SESSION[$this->keepUserPurviewTag] = $this->keepUserPurviewTag; $_SESSION[$this->keepUserPurviewTag] = $this->userPurview; $_SESSION[$this->keepAdminStyleTag] = $this->keepAdminStyleTag; $_SESSION[$this->keepAdminStyleTag] = $adminstyle; PutCookie('DedeUserID', $this->userID, 3600 * 24, '/'); PutCookie('DedeLoginTime', time(), 3600 * 24, '/');   希望本文所述对大家的dedecms建站有所帮助。