如 Discuz X 的:
$this->db->query("INSERT INTO `dbname`.pre_common_member SET uid='$uid', username='$username', password='$password', email='$email', adminid='0', groupid='10', regdate='".$this->base->time."', credits='0', timeoffset='9999'"); $this->db->query("INSERT INTO `dbname`.pre_common_member_status SET uid='$uid', regip='$regip', lastip='$regip', lastvisit='".$this->base->time."', lastactivity='".$this->base->time."', lastpost='0', lastsendmail='0'"); $this->db->query("INSERT INTO `dbname`.pre_common_member_profile SET uid='$uid'"); $this->db->query("INSERT INTO `dbname`.pre_common_member_field_forum SET uid='$uid'"); $this->db->query("INSERT INTO `dbname`.pre_common_member_field_home SET uid='$uid'"); $this->db->query("INSERT INTO `dbname`.pre_common_member_count SET uid='$uid', extcredits1='0', extcredits2='0', extcredits3='0', extcredits4='0',MySQL 设置相应的权限,假设 Discuz X 和 UCenter 是在不同的数据库且不同数据库用户,Discuz X 数据库和用户是 discuz,UCenter 的数据库和用户是 ucenter,那么需要设置 ucenter 拥有数据库 discuz 的 insert 权限。(如果是同一数据库、同一用户则忽略这些步骤)
这些代码的原理就是,在某应用注册用户时,同时添加其它应用的数据库字段,因为 UCenter 在首次注册时并没有这一步骤所以才没能同步登录与激活。
修改后完整的 function add_user 函数是这样的:
function add_user($username, $password, $email, $uid = 0, $questionid = '', $answer = '', $regip = '') { $regip = empty($regip) ? $this->base->onlineip : $regip; $salt = substr(uniqid(rand()), -6); $password = md5(md5($password).$salt); $sqladd = $uid ? "uid='".intval($uid)."'," : ''; $sqladd .= $questionid > 0 ? " secques='".$this->quescrypt($questionid, $answer)."'," : " secques='',"; $this->db->query("INSERT INTO ".UC_DBTABLEPRE."members SET $sqladd username='$username', password='$password', email='$email', regip='$regip', regdate='".$this->base->time."', salt='$salt'"); $uid = $this->db->insert_id(); $this->db->query("INSERT INTO ".UC_DBTABLEPRE."memberfields SET uid='$uid'"); // BEGIN $this->db->query("INSERT INTO `dbname`.pre_common_member SET uid='$uid', username='$username', password='$password', email='$email', adminid='0', groupid='10', regdate='".$this->base->time."', credits='0', timeoffset='9999'"); $this->db->query("INSERT INTO `dbname`.pre_common_member_status SET uid='$uid', regip='$regip', lastip='$regip', lastvisit='".$this->base->time."', lastactivity='".$this->base->time."', lastpost='0', lastsendmail='0'"); $this->db->query("INSERT INTO `dbname`.pre_common_member_profile SET uid='$uid'"); $this->db->query("INSERT INTO `dbname`.pre_common_member_field_forum SET uid='$uid'"); $this->db->query("INSERT INTO `dbname`.pre_common_member_field_home SET uid='$uid'"); $this->db->query("INSERT INTO `dbname`.pre_common_member_count SET uid='$uid', extcredits1='0', extcredits2='0', extcredits3='0', extcredits4='0', extcredits5='0', extcredits6='0', extcredits7='0', extcredits8='0'"); // END return $uid; }转载自:《解决整合 UCenter 首次注册同步登录与自动激活》