成功后设置cookie
//设置cookie ssetcookie('auth', authcode("$setarr[password]\t$setarr[uid]", 'ENCODE'), $cookietime); ssetcookie('loginuser', $passport['username'], 31536000); ssetcookie('_refer', '');
其中我用到最重要的是:api/uc.php文件中
function synlogin($get, $post) { global $_SGLOBAL; if(!API_SYNLOGIN) { return API_RETURN_FORBIDDEN; } //note 同步登录 API 接口 obclean(); 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 = $_SGLOBAL['db']->query("SELECT uid, username, password FROM ".tname('member')." WHERE uid='$uid'"); if($member = $_SGLOBAL['db']->fetch_array($query)) { include_once S_ROOT.'./source/function_space.php'; $member = saddslashes($member); $space = insertsession($member); //设置cookie ssetcookie('auth', authcode("$member[password]\t$member[uid]", 'ENCODE'), $cookietime); } ssetcookie('loginuser', $get['username'], $cookietime); }
if($member = $_SGLOBAL['db']->fetch_array($query)) {
include_once S_ROOT.'./source/function_space.php';
$member = saddslashes($member);
$space = insertsession($member);
//设置cookie
ssetcookie('auth', authcode("$member[password]\t$member[uid]", 'ENCODE'), $cookietime);
}
ssetcookie('loginuser', $get['username'], $cookietime);
验证:
//判断当前用户登录状态 function checkauth() { global $_SGLOBAL, $_SC, $_SCONFIG, $_SCOOKIE, $_SN; if($_SGLOBAL['mobile'] && $_GET['m_auth']) $_SCOOKIE['auth'] = $_GET['m_auth']; if($_SCOOKIE['auth']) { @list($password, $uid) = explode("\t", authcode($_SCOOKIE['auth'], 'DECODE')); $_SGLOBAL['supe_uid'] = intval($uid); if($password && $_SGLOBAL['supe_uid']) { // 查内存表 session表 $query = $_SGLOBAL['db']->query("SELECT * FROM ".tname('session')." WHERE uid='$_SGLOBAL[supe_uid]'"); if($member = $_SGLOBAL['db']->fetch_array($query)) { if($member['password'] == $password) { $_SGLOBAL['supe_username'] = addslashes($member['username']); $_SGLOBAL['session'] = $member; } else { $_SGLOBAL['supe_uid'] = 0; } } else { $query = $_SGLOBAL['db']->query("SELECT * FROM ".tname('member')." WHERE uid='$_SGLOBAL[supe_uid]'"); if($member = $_SGLOBAL['db']->fetch_array($query)) { if($member['password'] == $password) { $_SGLOBAL['supe_username'] = addslashes($member['username']); $session = array('uid' => $_SGLOBAL['supe_uid'], 'username' => $_SGLOBAL['supe_username'], 'password' => $password); include_once(S_ROOT.'./source/function_space.php'); insertsession($session);//登录 } else { $_SGLOBAL['supe_uid'] = 0; } } else { $_SGLOBAL['supe_uid'] = 0; } } } } if(empty($_SGLOBAL['supe_uid'])) { clearcookie(); } else { $_SGLOBAL['username'] = $member['username']; } }uchome2.0的登录验证机制越来越像Ucenter的了