After logging on to phpcms Weibo, do not register for the next time. if the session is out of date

Source: Internet
Author: User
Do not register again after you log on to phpcms weibo. do not register again after you log on to phpcms Weibo when your session is expired,
The idea is that after logging on to Weibo, you can directly write user nicknames and so on into the database,
Run the command again to check whether the account has been registered. However, after the logon is successful, the system always prompts that the session has expired. after the logon is successful, the session is normal.
The code is a bit long. Please check it out.

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 (oauthti Ti On $ 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 ); // obtain basic information such as user 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']) {// check whether the connect member is bound and has been bound to log on directly, unbound prompt registration/binding page $ where = array ('d d' => $ me ['id'], 'from' => 'sina '); $ r = $ this-> db-> get_one ($ where); // The connect user has been bound to this site user if (! Empty ($ r) {// read the user information of this site and perform the login operation $ 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, 'encoding', 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 ('_ nick Name', $ nickname, $ cookietime); $ forward = isset ($ _ GET ['Forward ']) &! Empty ($ _ GET ['Forward '])? $ _ GET ['Forward ']: 'Index. php? M = member & c = index'; showmessage (L ('login _ success '). $ synloginstr, $ forward);} else {// The binding registration page is displayed. $ _ SESSION = array (); $ _ SESSION ['connectiond'] = $ 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; // write data to the database $ 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 (), 'connected' => $ me ['id'], 'from' => 'sina '); // load the user module configuration $ member_setting = getcache ('Member _ setting'); if (! $ Member_setting ['allowregister ']) {showmessage (L ('deny _ register'), 'index. php? M = member & c = index & a = login ');} // obtain the user siteid $ siteid = isset ($ _ REQUEST ['siteid']) & trim ($ _ REQUEST ['siteid'])? Intval ($ _ REQUEST ['siteid']): 1; // filter non-current site member models $ modellist = getcache ('Member _ model', 'common '); 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; // set the default value if (array_key_exists ($ modelid, $ modellist )) {// Obtain the membership model form 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 (); // use the omnipotent field Filter 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 calls def again Ine ('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 _ url'] = 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 ); // obtain basic information such as user 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']) {// check whether the connect member is bound and has been bound to log on directly, the registration/binding page is not prompted. // $ where = array ('d d' => $ me ['id'], 'from' => 'Sina '); // $ r = $ this-> db-> get_one ($ where); $ where = "SELECT * FROM 'phpcms '. 'v9 _ member' WHERE 'd d' = ". $ me ['id']. "AND 'from' = 'sina 'limit 1"; $ r = $ this-> db-> query ($ where); // The connect user has been bound to this site user if (! Empty ($ r) {// read the user information of this site and perform the login operation $ 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, 'encoding', 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 ');}}

Reply content:

Which line of code Did you know about session expiration?

I didn't judge. I used his own code.
The idea is:
By default, it is used to determine whether a connect member is bound at a time. the user has been bound to log on directly. if not bound, the registration/binding page is displayed.

If it is already bound, log on directly,
No binding. after I write data to the database, I will call a judgment (that is, copy the judgment code once). at this time, it should have been bound, he will still prompt that a reply has expired...

After logging on to phpcms Weibo, do not register for the next time. The details about the outdated session are displayed. For more information, see PHP Chinese website (www.php1.cn )!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.