您现在的位置: 365建站网 > 365学习 > discuz x2 x1.5整合dedemcms phpcms免激活插件

discuz x2 x1.5整合dedemcms phpcms免激活插件

文章来源:365jz.com     点击数:101    更新时间:2015-10-02 23:53   参与评论

本插件主要解决在其他应用(如dedecms,PHPcms)注册的用户,在Discuz!X里自动激活。

修改步骤:
第一步:打开discuz!X1.5目录下/api/uc.php,在168行找到如下代码:

function synlogin($get, $post) {
global $_G;
if(!API_SYNLOGIN) {
return API_RETURN_FORBIDDEN;
}
header('P3P: CP="CURa ADMa DEVa PSAo PSDo OUR BUS UNI PUR INT DEM STA PRE COM NAV OTC NOI DSP COR"');
$cookietime = 31536000;
$uid = intval($get['uid']);
$query = DB::query("SELECT uid, username, password FROM ".DB::table('common_member')." WHERE uid='$uid'");
if($member = DB::fetch($query)) {
dsetcookie('auth', authcode("$member[password]\t$member[uid]", 'ENCODE'), $cookietime);
}
}
 
 
//start Discuz!X1.5免激活功能
function synlogin($get, $post) {
global $_G;
if(!API_SYNLOGIN) {
return API_RETURN_FORBIDDEN;
}
header('P3P: CP="CURa ADMa DEVa PSAo PSDo OUR BUS UNI PUR INT DEM STA PRE COM NAV OTC NOI DSP COR"');
$cookietime = 31536000;
$uid = intval($get['uid']);
$query = DB::query("SELECT uid, username, password FROM ".DB::table('common_member')." WHERE uid='$uid'");
if($member = DB::fetch($query)) {
dsetcookie('auth', authcode("$member[password]\t$member[uid]", 'ENCODE'), $cookietime);
}else{
$username = $get['username'];
$password = md5(time().rand(100000, 999999));
$email = $get['email'];
$ip = $_SERVER['REMOTE_ADDR'];
$time = time();

$userdata = array(
'uid' => $uid,
'username' => $username,
'password' => $password,
'email' => $email,
'adminid' => 0,
'groupid' => 10,
'regdate' => $time,
'credits' => 0,
'timeoffset' => 9999
);
DB::insert('common_member', $userdata);

$status_data = array(
'uid' => $uid,
'regip' => $ip,
'lastip' => $ip,
'lastvisit' => $time,
'lastactivity' => $time,
'lastpost' => 0,
'lastsendmail' => 0,
);
DB::insert('common_member_status', $status_data);
DB::insert('common_member_profile', array('uid' => $uid));
DB::insert('common_member_field_forum', array('uid' => $uid));
DB::insert('common_member_field_home', array('uid' => $uid));

$query = DB::query("SELECT uid, username, password FROM ".DB::table('common_member')." WHERE uid='$uid'");
if($member = DB::fetch($query)) {
dsetcookie('auth', authcode("$member[password]\t$member[uid]", 'ENCODE'), $cookietime);
}
}
}
// end


注:以上代码为DZ论坛上ANDY提供。经笔者测试分析,以上代码有以下不足:
1、虽然免激活了,但是那个用户发帖或者回复后提示:作者被禁止或删除 内容自动屏蔽。
2、论坛中“欢迎新会员”不会自动更新。
3、自动登录后EMIL没有同步,需要在DZ中登录一次才会同步。

以下是对原代码进行修改后的完善版

//start Discuz!X1.5免激活功能 BY Jongye
function synlogin($get, $post) {
global $_G;

if(!API_SYNLOGIN) {
return API_RETURN_FORBIDDEN;
}

header('P3P: CP="CURa ADMa DEVa PSAo PSDo OUR BUS UNI PUR INT DEM STA PRE COM NAV OTC NOI DSP COR"');

$cookietime = 31536000;
$uid = intval($get['uid']);
$query = DB::query("SELECT uid, username, password FROM ".DB::table('common_member')." WHERE uid='$uid'");
if($member = DB::fetch($query)) {
dsetcookie('auth', authcode("$member[password]\t$member[uid]", 'ENCODE'), $cookietime);
}else{

$username = $get['username'];
$query = DB::query("SELECT uid, username, password,email FROM ".DB::table('ucenter_members')." WHERE username='$username'");
$member = DB::fetch($query);
$password = $member['password'];
$email = $member['email'];
$ip = $_SERVER['REMOTE_ADDR'];
$time = time();


$userdata = array(
'uid' => $uid,
'username' => $username,
'password' => $password,
'email' => $email,
'adminid' => 0,
'groupid' => 10,
'regdate' => $time,
'credits' => 0,
'timeoffset' => 9999
);
DB::insert('common_member', $userdata);

$status_data = array(
'uid' => $uid,
'regip' => $ip,
'lastip' => $ip,
'lastvisit' => $time,
'lastactivity' => $time,
'lastpost' => 0,
'lastsendmail' => 0,
);
DB::insert('common_member_status', $status_data);
DB::insert('common_member_profile', array('uid' => $uid));
DB::insert('common_member_field_forum', array('uid' => $uid));
DB::insert('common_member_field_home', array('uid' => $uid));
DB::insert('common_member_count', array('uid' => $uid));
DB::query("UPDATE ".DB::table('common_setting')." SET svalue='$username' WHERE skey='lastmember'");

$query = DB::query("SELECT uid, username, password FROM ".DB::table('common_member')." WHERE uid='$uid'");
if($member = DB::fetch($query)) {
dsetcookie('auth', authcode("$member[password]\t$member[uid]", 'ENCODE'), $cookietime);
}
}

}
// end 

如对本文有疑问,请提交到交流论坛,广大热心网友会为你解答!! 点击进入论坛


发表评论 (101人查看2条评论)
请自觉遵守互联网相关的政策法规,严禁发布色情、暴力、反动的言论。
用户名: 验证码: 点击我更换图片
最新评论
------分隔线----------------------------