phpcms微博登陆后,不要二次注册,出现会话过时,
思路是 微博登录后,直接把用户昵称等写入数据库,
然后再执行一次,判断是否注册过,但是提示登录成功之后,总提示一次会话过期.再次登录后正常.
代码有点长,麻烦看下.
public function public_sina_login() { define('WB_AKEY', pc_base::load_config('system', 'sina_akey')); define('WB_SKEY', pc_base::load_config('system', 'sina_skey')); define('WEB_CALLBACK', APP_PATH.'index.php?m=member&c=index&a=public_sina_login&callback=1'); pc_base::load_app_class('saetv2.ex', '' ,0); $this->_session_start(); if(isset($_GET['callback']) && trim($_GET['callback'])) { $o = new SaeTOAuthV2(WB_AKEY, WB_SKEY); if (isset($_REQUEST['code'])) { $keys = array(); $keys['code'] = $_REQUEST['code']; $keys['redirect_uri'] = WEB_CALLBACK; try { $token = $o->getAccessToken('code', $keys); } catch (OAuthException $e) { } } if ($token) { $_SESSION['token'] = $token; } $c = new SaeTClientV2(WB_AKEY, WB_SKEY, $_SESSION['token']['access_token'] ); $ms = $c->home_timeline(); // done $uid_get = $c->get_uid(); $uid = $uid_get['uid']; $me = $c->show_user_by_id( $uid);//根据ID获取用户等基本信息 if(CHARSET != 'utf-8') { $me['name'] = iconv('utf-8', CHARSET, $me['name']); $me['location'] = iconv('utf-8', CHARSET, $me['location']); $me['description'] = iconv('utf-8', CHARSET, $me['description']); $me['screen_name'] = iconv('utf-8', CHARSET, $me['screen_name']); } if(!empty($me['id'])) { //检查connect会员是否绑定,已绑定直接登录,未绑定提示注册/绑定页面 $where = array('connectid'=>$me['id'], 'from'=>'sina'); $r = $this->db->get_one($where); //connect用户已经绑定本站用户 if(!empty($r)) { //读取本站用户信息,执行登录操作 $password = $r['password']; $this->_init_phpsso(); $synloginstr = $this->client->ps_member_synlogin($r['phpssouid']); $userid = $r['userid']; $groupid = $r['groupid']; $username = $r['username']; $nickname = empty($r['nickname']) ? $username : $r['nickname']; $this->db->update(array('lastip'=>ip(), 'lastdate'=>SYS_TIME, 'nickname'=>$me['name']), array('userid'=>$userid)); if(!$cookietime) $get_cookietime = param::get_cookie('cookietime'); $_cookietime = $cookietime ? intval($cookietime) : ($get_cookietime ? $get_cookietime : 0); $cookietime = $_cookietime ? TIME + $_cookietime : 0; $phpcms_auth = sys_auth($userid."\t".$password, 'ENCODE', get_auth_key('login')); param::set_cookie('auth', $phpcms_auth, $cookietime); param::set_cookie('_userid', $userid, $cookietime); param::set_cookie('_username', $username, $cookietime); param::set_cookie('_groupid', $groupid, $cookietime); param::set_cookie('cookietime', $_cookietime, $cookietime); param::set_cookie('_nickname', $nickname, $cookietime); $forward = isset($_GET['forward']) && !empty($_GET['forward']) ? $_GET['forward'] : 'index.php?m=member&c=index'; showmessage(L('login_success').$synloginstr, $forward); } else { //弹出绑定注册页面 $_SESSION = array(); $_SESSION['connectid'] = $me['id']; $_SESSION['from'] = 'sina'; $connect_username = $me['name']; //SELECT max(userid) maxid FROM user $where="SELECT MAX(phpssouid) maxid FROM `v9_member` WHERE 1"; $info = $this->db->query($where); $row = mysql_fetch_object($info); // $row =Myspl_fetch_array($info,MYSQL_NUM); $maxid = $row->maxid; $phpssouid = $maxid+1; //写入数据库 $this->db->insert(array('nickname'=>$me['name'],'regip'=>ip(),'regdate'=>SYS_TIME,'img'=>$me['avatar_large'],'phpssouid'=>$phpssouid,'password'=>'','groupid' =>'2','lastdate'=>SYS_TIME, 'lastip'=>ip(),'connectid'=>$me['id'],'from'=>'sina')); //加载用户模块配置 $member_setting = getcache('member_setting'); if(!$member_setting['allowregister']) { showmessage(L('deny_register'), 'index.php?m=member&c=index&a=login'); } //获取用户siteid $siteid = isset($_REQUEST['siteid']) && trim($_REQUEST['siteid']) ? intval($_REQUEST['siteid']) : 1; //过滤非当前站点会员模型 $modellist = getcache('member_model', 'commons'); foreach($modellist as $k=>$v) { if($v['siteid']!=$siteid || $v['disabled']) { unset($modellist[$k]); } } if(empty($modellist)) { showmessage(L('site_have_no_model').L('deny_register'), HTTP_REFERER); } $modelid = 10; //设定默认值 if(array_key_exists($modelid, $modellist)) { //获取会员模型表单 require CACHE_MODEL_PATH.'member_form.class.php'; $member_form = new member_form($modelid); $this->db->set_model($modelid); $forminfos = $forminfos_arr = $member_form->get(); //万能字段过滤 foreach($forminfos as $field=>$info) { if($info['isomnipotent']) { unset($forminfos[$field]); } else { if($info['formtype']=='omnipotent') { foreach($forminfos_arr as $_fm=>$_fm_value) { if($_fm_value['isomnipotent']) { $info['form'] = str_replace('{'.$_fm.'}',$_fm_value['form'], $info['form']); } } $forminfos[$field]['form'] = $info['form']; } } } //$formValidator = $member_form->formValidator; //zaizai再次调用 define('WB_AKEY', pc_base::load_config('system', 'sina_akey')); define('WB_SKEY', pc_base::load_config('system', 'sina_skey')); define('WEB_CALLBACK', APP_PATH.'index.php?m=member&c=index&a=public_sina_login&callback=1'); pc_base::load_app_class('saetv2.ex', '' ,0); $this->_session_start(); $o = new SaeTOAuthV2(WB_AKEY, WB_SKEY); if (isset($_REQUEST['code'])) { $keys = array(); $keys['code'] = $_REQUEST['code']; $keys['redirect_uri'] = WEB_CALLBACK; try { $token = $o->getAccessToken('code', $keys); } catch (OAuthException $e) { } } if ($token) { $_SESSION['token'] = $token; } $c = new SaeTClientV2(WB_AKEY, WB_SKEY, $_SESSION['token']['access_token'] ); $ms = $c->home_timeline(); // done $uid_get = $c->get_uid(); $uid = $uid_get['uid']; $me = $c->show_user_by_id( $uid);//根据ID获取用户等基本信息 if(CHARSET != 'utf-8') { $me['name'] = iconv('utf-8', CHARSET, $me['name']); $me['location'] = iconv('utf-8', CHARSET, $me['location']); $me['description'] = iconv('utf-8', CHARSET, $me['description']); $me['screen_name'] = iconv('utf-8', CHARSET, $me['screen_name']); } if(!empty($me['id'])) { //检查connect会员是否绑定,已绑定直接登录,未绑定提示注册/绑定页面 // $where = array('connectid' => $me['id'], 'from' => 'sina'); // $r = $this->db->get_one($where); $where = " SELECT * FROM `phpcms`.`v9_member` WHERE `connectid` = ".$me['id']." AND `from` = 'sina' LIMIT 1 "; $r = $this->db->query($where); //connect用户已经绑定本站用户 if (!empty($r)) { //读取本站用户信息,执行登录操作 $password = $r['password']; $this->_init_phpsso(); $synloginstr = $this->client->ps_member_synlogin($r['phpssouid']); $userid = $r['userid']; $groupid = $r['groupid']; $username = $r['username']; $nickname = empty($r['nickname']) ? $username : $r['nickname']; //$this->db->update(array('lastip' => ip(), 'lastdate' => SYS_TIME, 'nickname' => $me['name']), array('userid' => $userid)); if (!$cookietime) $get_cookietime = param::get_cookie('cookietime'); $_cookietime = $cookietime ? intval($cookietime) : ($get_cookietime ? $get_cookietime : 0); $cookietime = $_cookietime ? TIME + $_cookietime : 0; $phpcms_auth = sys_auth($userid . "\t" . $password, 'ENCODE', get_auth_key('login')); param::set_cookie('auth', $phpcms_auth, $cookietime); param::set_cookie('_userid', $userid, $cookietime); param::set_cookie('_username', $username, $cookietime); param::set_cookie('_groupid', $groupid, $cookietime); param::set_cookie('cookietime', $_cookietime, $cookietime); param::set_cookie('_nickname', $nickname, $cookietime); $forward = isset($_GET['forward']) && !empty($_GET['forward']) ? $_GET['forward'] : 'index.php?m=member&c=index'; showmessage(L('login_success') . $synloginstr, $forward); } } } include template('member', 'connect'); } } else { showmessage(L('login_failure'), 'index.php?m=member&c=index&a=login'); } } else { $o = new SaeTOAuthV2(WB_AKEY, WB_SKEY); $aurl = $o->getAuthorizeURL(WEB_CALLBACK); include template('member', 'connect_sina'); } }
回复内容:
会话过期 你是在那一行代码判断的?
我没去判断,我用的他自带的代码
思路是:
默认是判断 一次 //检查connect会员是否绑定,已绑定直接登录,未绑定提示注册/绑定页面
如果已经绑定,则直接登录,
没绑定,我会在写入数据库后,在调用一次判断(就是把判断的代码在复制过来一次,),这时候应该已经绑定了,他还是会在提示一次回话过期呢...
以上就是phpcms微博登陆后,不要二次注册,出现会话过时的详解的内容,更多相关内容请关注PHP中文网(www.php.cn)!

Thedifferencebetweenunset()andsession_destroy()isthatunset()clearsspecificsessionvariableswhilekeepingthesessionactive,whereassession_destroy()terminatestheentiresession.1)Useunset()toremovespecificsessionvariableswithoutaffectingthesession'soveralls

Stickysessionsensureuserrequestsareroutedtothesameserverforsessiondataconsistency.1)SessionIdentificationassignsuserstoserversusingcookiesorURLmodifications.2)ConsistentRoutingdirectssubsequentrequeststothesameserver.3)LoadBalancingdistributesnewuser

PHPoffersvarioussessionsavehandlers:1)Files:Default,simplebutmaybottleneckonhigh-trafficsites.2)Memcached:High-performance,idealforspeed-criticalapplications.3)Redis:SimilartoMemcached,withaddedpersistence.4)Databases:Offerscontrol,usefulforintegrati

Session in PHP is a mechanism for saving user data on the server side to maintain state between multiple requests. Specifically, 1) the session is started by the session_start() function, and data is stored and read through the $_SESSION super global array; 2) the session data is stored in the server's temporary files by default, but can be optimized through database or memory storage; 3) the session can be used to realize user login status tracking and shopping cart management functions; 4) Pay attention to the secure transmission and performance optimization of the session to ensure the security and efficiency of the application.

PHPsessionsstartwithsession_start(),whichgeneratesauniqueIDandcreatesaserverfile;theypersistacrossrequestsandcanbemanuallyendedwithsession_destroy().1)Sessionsbeginwhensession_start()iscalled,creatingauniqueIDandserverfile.2)Theycontinueasdataisloade

Absolute session timeout starts at the time of session creation, while an idle session timeout starts at the time of user's no operation. Absolute session timeout is suitable for scenarios where strict control of the session life cycle is required, such as financial applications; idle session timeout is suitable for applications that want users to keep their session active for a long time, such as social media.

The server session failure can be solved through the following steps: 1. Check the server configuration to ensure that the session is set correctly. 2. Verify client cookies, confirm that the browser supports it and send it correctly. 3. Check session storage services, such as Redis, to ensure that they are running normally. 4. Review the application code to ensure the correct session logic. Through these steps, conversation problems can be effectively diagnosed and repaired and user experience can be improved.

session_start()iscrucialinPHPformanagingusersessions.1)Itinitiatesanewsessionifnoneexists,2)resumesanexistingsession,and3)setsasessioncookieforcontinuityacrossrequests,enablingapplicationslikeuserauthenticationandpersonalizedcontent.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Atom editor mac version download
The most popular open source editor

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

WebStorm Mac version
Useful JavaScript development tools
