$phpBB->careate_session($nick,$password);//和phpbb共享登录状态
大体的想法是这样的
关闭论坛的注册功能,将phpbb 的login_box函数的重定向指定到主站上,这样,只要提示用户注册或者登录,用户只能从zen-cart主站上进行
然后就是创建cookie和session的问题了
找到“zen-cart/includes/classes/class.phpbb.php"往该类增加三个函数
/**--二次开发--**/
function create_sess_id($len=32){//产生一个session_id
list($u, $s) = explode(' ', microtime());
$time = (float)$u + (float)$s;// 获取当前时间的微秒
$rand_num = rand(100000, 999999);
$rand_num = rand($rand_num, $time);
mt_srand($rand_num);
$rand_num = mt_rand();// 产生一个随机数
$sess_id = md5( md5($time). md5($rand_num) );// 产生SessionID
$sess_id = substr($sess_id, 0, $len);
return $sess_id;// 截取指定需要长度的SessionID
}
function get_userid_by_username($nick){//通过用户名获得用户ID
$sql="select `user_id` from ". $this->phpBB['users_table'] ." where `username`='".$nick."'";
$result=$this->db_phpbb->Execute($sql);
$user_id='';
while (!$result->EOF) {
$user_id=$result->fields['user_id'];
$result->MoveNext();
}
return $user_id;
}
function careate_session($username,$password){//产生一个phpBB的session
if(!$username || !$password){
return ;
}
$sessionIp='';
$cookie_path='';
$cookieName='';
$session_id=$this->create_sess_id(32);
$sql="select * from `".$this->phpBB['config_table']."` where `config_name` in ('cookie_domain','cookie_name','cookie_path')";
//exit($sql);
$result=$this->db_phpbb->Execute($sql);
while (!$result->EOF) {
if($result->fields['config_name']=='cookie_domain'){
$sessionIp=$result->fields['config_value'];
}
if($result->fields['config_name']=='cookie_path'){
$cookie_path=$result->fields['config_value'];
}
if($result->fields['config_name']=='cookie_name'){
$cookieName=$result->fields['config_value'];
}
$result->MoveNext();
}
//exit($cookieName.'--'.$sessionIp.'--'.$cookie_path);
$userBrowserInfo= $_SERVER["HTTP_USER_AGENT"];
$userIpAdd=empty($_SERVER["HTTP_CLIENT_IP"])?'127.0.0.1':$_SERVER["HTTP_CLIENT_IP"];
$cmd_username=$username;
$user_id=$this->get_userid_by_username($cmd_username);
//ob_clean();//清除输出
//zen_setcookie('cookie_test', 'please_accept_for_session', time()+60*60*24*30, '/', (zen_not_null($current_domain) ? $current_domain : ''));
zen_setcookie($cookieName.'_u',$user_id,time()+100000000,'','',false);
//往Cookies里插入SessionID信息
zen_setcookie($cookieName.'_sid',$session_id,time()+100000000,'','',false);
//往phpb_sessions表中插入Session信息
$session_table=$this->phpBB['table_prefix'].'sessions';
$sqlcommand="insert into ".$session_table."(session_id,session_user_id,session_last_visit,session_start,session_time,session_ip,session_browser,session_page)";
$sqlcommand.=" values('$session_id',$user_id,'".time()."','".time()."','".time()."','$userIpAdd','$userBrowserInfo','index.php')";
//exit($sqlcommand);
$this->db_phpbb->Execute($sqlcommand);
}
$zco_notifier->notify('NOTIFY_LOGIN_SUCCESS');
//二次开发,同步登录
if ($phpBB->phpBB['installed'] == true) {
$phpBB->careate_session($email_address,$password);
}
//二次开发,同步登录
注意这里$email_address代表用户名,我这里把zen-cart改成只能用email登录,所以用户名就是eamil
找到“zen-cart\includes\modules\creat_account.php”在大概317行
// phpBB create account
if ($phpBB->phpBB['installed'] == true) {
$phpBB->phpbb_create_account($nick, $password, $email_address);
}
$phpBB->careate_session($nick,$password);//和phpbb共享登录状态
最后修改为
// phpBB create account
if ($phpBB->phpBB['installed'] == true) {
$phpBB->phpbb_create_account($nick, $password, $email_address);
$phpBB->careate_session($nick,$password);//和phpbb共享登录状态
}