在XAMPP上安装DEDECMS,但小明尝试登录后台时,首先是验证码错误,解决验证码问题之后成功登录,但后台一片空白,连任何错误提示信息都没有。查看了PHP、APACHE、DEDECMS运行错误,却没有任何相关信息。
问题排除
1、那么会不会是PHP环境没有安装好呢?
由于DEDECMS前台默认是php,如果php没有安装好,那么前台也应该是空白,但前台显示正常。
2、会不会是php禁用了某些函数,导致php程序不能执行呢?
如果禁用了某些函数,那么PHP、APACHE、DEDECMS等错误日志中应该会提示,查看了所有,依然没有。
3、会不会php某些函数不被支持呢?
找到处理登录操作的 D:\xampp\htdocs\dedecms_test\include\userlogin.class.php 文件,找几个特殊的函数进行阅读,好像找到了。有不被支持的函数。
问题分析
编辑 /include/userlogin.class.php 文件,找到 function keepUser() 函数,大概 281 行:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
/**
* 保持用户的会话状态
*
* @access public
* @return int 成功返回 1 ,失败返回 -1
*/
function keepUser()
{
if($this->userID != '' && $this->userType != '')
{
global $admincachefile,$adminstyle;
if(empty($adminstyle)) $adminstyle = 'dedecms';
@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, '/');
$this->ReWriteAdminChannel();
return 1;
}
else
{
return -1;
}
}
其中,session_register 函数是已经被 php 抛弃了, php 这样解释道(原文 http://www.php.net/manual/zh/function.session-register.php):
该函数,接受一个可变数组参数。它主要用于创建一个或多个全局 SESSION 会话,支持范围是 PHP 4, PHP 5 < 5.4.0,我们的php版本是低于 5.4.0 吗?
在 D:\xampp\htdocs\dedecms_test 中创建 phpinfo.php 文件,文件内容:
1
2
3
<?php
echo phpinfo();
?>
浏览器输入:http://localhost/phpinfo.php,悲催了。版本果然高于 5.4.0!
既然如此,我们把过时的函数删除是不是就可以了呢?嗯,试试!
解决方案
编辑 /include/userlogin.class.php(大概 281 行),将:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
/**
* 保持用户的会话状态
*
* @access public
* @return int 成功返回 1 ,失败返回 -1
*/
function keepUser()
{
if($this->userID != '' && $this->userType != '')
{
global $admincachefile,$adminstyle;
if(empty($adminstyle)) $adminstyle = 'dedecms';
@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, '/');
$this->ReWriteAdminChannel();
return 1;
}
else
{
return -1;
}
}
替换为(其实就是行注释 session_register):
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
/**
* 保持用户的会话状态
*
* @access public
* @return int 成功返回 1 ,失败返回 -1
*/
function keepUser()
{
if($this->userID != '' && $this->userType != '')
{
global $admincachefile,$adminstyle;
if(empty($adminstyle)) $adminstyle = 'dedecms';
// @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, '/');
$this->ReWriteAdminChannel();
return 1;
}
else
{
return -1;
}
}
好,保存文件尝试登录。笔者成功登录后,发现不能注销登录,一点注销登录有出现空白,看来又是这个问题了。好吧,继续解决DEDECMS后台不能注销登录,出现空白页面问题。
解决后台不能注销登录
当我们点击注销页面,它请求 http://localhost/dede/exit.php 到这个页面去了,打开 /dede/exit.php 文件,关键代码:
1
2
3
require_once(DEDEINC.'/userlogin.class.php');
$cuserLogin = new userLogin();
$cuserLogin->exitUser(); // 执行 userlogin.class.php 中的 exitUser(); 函数。
/include/userlogin.class.php 中的 exitUser(); 函数代码:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
/**
* 结束用户的会话状态
*
* @access public
* @return void
*/
function exitUser()
{
ClearMyAddon();
@session_unregister($this->keepUserIDTag);
@session_unregister($this->keepUserTypeTag);
@session_unregister($this->keepUserChannelTag);
@session_unregister($this->keepUserNameTag);
@session_unregister($this->keepUserPurviewTag);
DropCookie('dedeAdmindir');
DropCookie('DedeUserID');
DropCookie('DedeLoginTime');
$_SESSION = array();
}
从 PHP 文档(原文:http://www.php.net/manual/zh/function.session-unregister.php)中可以看到,session_unregister 函数又被抛弃了…
那咋办?注释代码吗?这个不行,注释就不能退出登录了…,这个php文档底部似乎有个解决方案,原文如下:
1
2
3
4
5
6
If globals is on, you'll have to unset the $_SESSION[varname] as well as the $varname.
Like:
unset($_SESSION[varname]);
unset($varname);
我们把 session_unregister 替换成 unset 试试吧,因此我们将:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
/**
* 结束用户的会话状态
*
* @access public
* @return void
*/
function exitUser()
{
ClearMyAddon();
@session_unregister($this->keepUserIDTag);
@session_unregister($this->keepUserTypeTag);
@session_unregister($this->keepUserChannelTag);
@session_unregister($this->keepUserNameTag);
@session_unregister($this->keepUserPurviewTag);
DropCookie('dedeAdmindir');
DropCookie('DedeUserID');
DropCookie('DedeLoginTime');
$_SESSION = array();
}
替换成:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
/**
* 结束用户的会话状态
*
* @access public
* @return void
*/
function exitUser()
{
ClearMyAddon();
unset ($this->keepUserIDTag);
unset ($this->keepUserTypeTag);
unset ($this->keepUserChannelTag);
unset ($this->keepUserNameTag);
unset ($this->keepUserPurviewTag);
DropCookie('dedeAdmindir');
DropCookie('DedeUserID');
DropCookie('DedeLoginTime');
$_SESSION = array();
}
如你所想,问题解决了!可能其它地方还存在这样的问题,本文就当做个抛砖引玉~