前夫哥 發表於 2024-2-28 00:00:00

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

<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
        本文实例讲述了DEDECMS在PHP5.4不能正常运行的解决方法。分享给大家供大家参考。具体分析如下:</p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
        PHP5.4是公开发行的PHP程式最新版本,其执行速度和内存占用等相比PHP5.3而言有10%~30%的性能提升,所以笔者也一直想在实际环境中试运行PHP5.4(PHP5.4目前最新的版本为5.4.9)。</p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
        棘手的是与PHP5.2升级到PHP5.3有所不同的是,从5.3到5.4之间似乎变化不少,这也造成了笔者在将DEDECMS系统迁移到PHP5.4.x平台的时候出现了前台500错误后台直接空白的情况,当时也没有深究便换回PHP5.3了。</p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
        最近仔细查了下相关资料,发现主要是因为目前DEDECMS代码中使用了PHP5.4中弃用的一些函数,主要如下:</p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
        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</p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
        其中造成DEDECMS5.7无法正常运行的函数便是session_register。</p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
        <strong>网上实测有效的方法有如下两种:</strong></p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
        第一种方法申明将此函数废弃,在include/userlogin.class.php中加入如下代码:<br>
         </p>
<div class="msgheader" style='margin: 3px auto 0px; padding: 0px 3px; outline: none; line-height: 21.6px; clear: both; border-width: 1px; border-style: solid; border-color: rgb(0, 153, 204); background: rgb(246, 251, 255); overflow: hidden; font-family: tahoma, arial, "Microsoft YaHei";'>
        <div class="right">
                <span><u>复制代码</u></span>
</div>
        代码如下:</div>
<div class="msgborder" id="phpcode9" style='margin: 0px auto 3px; padding: 0px 3px; outline: none; line-height: 25.2px; font-size: 14px; clear: both; border-right: 1px solid rgb(0, 153, 204); background: rgb(221, 237, 251); overflow: hidden; border-left: 1px solid rgb(0, 153, 204); word-break: break-all; border-bottom: 1px solid rgb(0, 153, 204); word-wrap: break-word; font-family: tahoma, arial, "Microsoft YaHei";'>
        function session_register() <br>
        { <br>
        return true; <br>
        }</div>
<br style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'><span style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'>第二种方法是该该页中的函数代码替换,被替换代码大致在287到308行之间,代码如下:</span><br style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'><br style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'><div class="msgheader" style='margin: 3px auto 0px; padding: 0px 3px; outline: none; line-height: 21.6px; clear: both; border-width: 1px; border-style: solid; border-color: rgb(0, 153, 204); background: rgb(246, 251, 255); overflow: hidden; font-family: tahoma, arial, "Microsoft YaHei";'>
        <div class="right">
                <span><u>复制代码</u></span>
</div>
        代码如下:</div>
<div class="msgborder" id="phpcode10" style='margin: 0px auto 3px; padding: 0px 3px; outline: none; line-height: 25.2px; font-size: 14px; clear: both; border-right: 1px solid rgb(0, 153, 204); background: rgb(221, 237, 251); overflow: hidden; border-left: 1px solid rgb(0, 153, 204); word-break: break-all; border-bottom: 1px solid rgb(0, 153, 204); word-wrap: break-word; font-family: tahoma, arial, "Microsoft YaHei";'>
        @session_register($this-&gt;keepUserIDTag); <br>
        $_SESSION[$this-&gt;keepUserIDTag] = $this-&gt;userID; <br>
        @session_register($this-&gt;keepUserTypeTag); <br>
        $_SESSION[$this-&gt;keepUserTypeTag] = $this-&gt;userType; <br>
        @session_register($this-&gt;keepUserChannelTag); <br>
        $_SESSION[$this-&gt;keepUserChannelTag] = $this-&gt;userChannel; <br>
        @session_register($this-&gt;keepUserNameTag); <br>
        $_SESSION[$this-&gt;keepUserNameTag] = $this-&gt;userName; <br>
        @session_register($this-&gt;keepUserPurviewTag); <br>
        $_SESSION[$this-&gt;keepUserPurviewTag] = $this-&gt;userPurview; <br>
        @session_register($this-&gt;keepAdminStyleTag); <br>
        $_SESSION[$this-&gt;keepAdminStyleTag] = $adminstyle; <br>
        PutCookie('DedeUserID', $this-&gt;userID, 3600 * 24, '/'); <br>
        PutCookie('DedeLoginTime', time(), 3600 * 24, '/');</div>
<br style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'><span style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'>替换为如下代码:</span><br style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'><br style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'><div class="msgheader" style='margin: 3px auto 0px; padding: 0px 3px; outline: none; line-height: 21.6px; clear: both; border-width: 1px; border-style: solid; border-color: rgb(0, 153, 204); background: rgb(246, 251, 255); overflow: hidden; font-family: tahoma, arial, "Microsoft YaHei";'>
        <div class="right">
                <span><u>复制代码</u></span>
</div>
        代码如下:</div>
<div class="msgborder" id="phpcode11" style='margin: 0px auto 3px; padding: 0px 3px; outline: none; line-height: 25.2px; font-size: 14px; clear: both; border-right: 1px solid rgb(0, 153, 204); background: rgb(221, 237, 251); overflow: hidden; border-left: 1px solid rgb(0, 153, 204); word-break: break-all; border-bottom: 1px solid rgb(0, 153, 204); word-wrap: break-word; font-family: tahoma, arial, "Microsoft YaHei";'>
        global $admincachefile,$adminstyle; <br>
        if(emptyempty($adminstyle)) $adminstyle = 'dedecms'; <br>
        $_SESSION[$this-&gt;keepUserIDTag] = $this-&gt;keepUserIDTag; <br>
        $_SESSION[$this-&gt;keepUserIDTag] = $this-&gt;userID; <br>
        $_SESSION[$this-&gt;keepUserTypeTag] = $this-&gt;keepUserTypeTag; <br>
        $_SESSION[$this-&gt;keepUserTypeTag] = $this-&gt;userType; <br>
        $_SESSION[$this-&gt;keepUserChannelTag] = $this-&gt;keepUserChannelTag; <br>
        $_SESSION[$this-&gt;keepUserChannelTag] = $this-&gt;userChannel; <br>
        $_SESSION[$this-&gt;keepUserNameTag] = $this-&gt;keepUserNameTag; <br>
        $_SESSION[$this-&gt;keepUserNameTag] = $this-&gt;userName; <br>
        $_SESSION[$this-&gt;keepUserPurviewTag] = $this-&gt;keepUserPurviewTag; <br>
        $_SESSION[$this-&gt;keepUserPurviewTag] = $this-&gt;userPurview; <br>
        $_SESSION[$this-&gt;keepAdminStyleTag] = $this-&gt;keepAdminStyleTag; <br>
        $_SESSION[$this-&gt;keepAdminStyleTag] = $adminstyle; <br>
        PutCookie('DedeUserID', $this-&gt;userID, 3600 * 24, '/'); <br>
        PutCookie('DedeLoginTime', time(), 3600 * 24, '/');</div>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
         </p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
        希望本文所述对大家的dedecms建站有所帮助。</p>
頁: [1]
查看完整版本: DEDECMS在PHP5.4不能正常运行的解决方法