function login_init($sid = FALSE, $no_auto_guest_login = FALSE) { global $currentuinfo; global $loginok; global $currentuser_num; global $currentuinfo_num; global $currentuser; global $utmpnum; global $setboard; global $fromhost; global $fullfromhost; $currentuinfo_tmp = array(); $compat_telnet = 0; $sessionid = ""; if ($sid) { if (is_string($sid)) { $sessionid = $sid; } else { @($sessionid = $_GET["sid"]); if (!$sessionid) { @($sessionid = $_POST["sid"]); } if (!$sessionid) { @($sessionid = $_COOKIE["sid"]); } settype($sessionid, "string"); } } if ($sessionid && strlen($sessionid) == 9) { $utmpnum = decodesessionchar($sessionid[0]) + decodesessionchar($sessionid[1]) * 36 + decodesessionchar($sessionid[2]) * 36 * 36; $utmpkey = decodesessionchar($sessionid[3]) + decodesessionchar($sessionid[4]) * 36 + decodesessionchar($sessionid[5]) * 36 * 36 + decodesessionchar($sessionid[6]) * 36 * 36 * 36 + decodesessionchar($sessionid[7]) * 36 * 36 * 36 * 36 + decodesessionchar($sessionid[8]) * 36 * 36 * 36 * 36 * 36; $userid = ''; $compat_telnet = 1; } else { @($utmpkey = $_COOKIE["UTMPKEY"]); @($utmpnum = $_COOKIE["UTMPNUM"]); @($userid = $_COOKIE["UTMPUSERID"]); } if ($utmpkey) { if (($ret = bbs_setonlineuser($userid, intval($utmpnum), intval($utmpkey), $currentuinfo_tmp, $compat_telnet)) == 0) { $loginok = 1; $currentuinfo_num = bbs_getcurrentuinfo(); $currentuser_num = bbs_getcurrentuser($currentuser); } else { $utmpkey = ""; } } // add by stiger, 如果登录失败就继续用guest登录 if (!$sessionid && !$utmpkey && !$no_auto_guest_login) { set_fromhost(); $error = bbs_wwwlogin(0, $fromhost, $fullfromhost); if ($error == 2 || $error == 0) { $data = array(); $num = bbs_getcurrentuinfo($data); setcookie("UTMPKEY", $data["utmpkey"], 0, "/"); setcookie("UTMPNUM", $num, 0, "/"); setcookie("UTMPUSERID", $data["userid"], 0, "/"); header("Set-KBSRC: /"); @($utmpkey = $data["utmpkey"]); @($utmpnum = $num); @($userid = $data["userid"]); $compat_telnet = 1; } //guest 登录成功,设置一下 if ($utmpkey != "") { if (($ret = bbs_setonlineuser($userid, intval($utmpnum), intval($utmpkey), $currentuinfo_tmp, $compat_telnet)) == 0) { $loginok = 1; $currentuinfo_num = bbs_getcurrentuinfo(); $currentuser_num = bbs_getcurrentuser($currentuser); } } } $currentuinfo = $currentuinfo_tmp; settype($utmpnum, "integer"); if ($loginok != 1 && !$no_auto_guest_login) { delete_all_cookie(); cache_header("nocache"); ?> <html> <head><meta http-equiv="Content-Type" content="text/html; charset=gb2312" /></head> <body>您还没有登录,或者你发呆时间过长被服务器清除。 请重新<a href="index.html" target="_top">登录</a>。</body> </html> <?php exit; } if ($loginok == 1 && (isset($setboard) && $setboard == 1)) { bbs_set_onboard(0, 0); } return $sessionid; }
function login_init() { global $currentuinfo; global $loginok; global $currentuser_num; global $currentuinfo_num; global $currentuser; global $utmpnum; global $setboard; global $fromhost; $currentuinfo_tmp = array(); set_fromhost(); $compat_telnet = 0; @($sessionid = $_GET["sid"]); //TODO: add the check of telnet compat if ($sessionid != '' && $_SERVER['PHP_SELF'] == '/bbscon.php') { $utmpnum = decodesessionchar($sessionid[0]) + decodesessionchar($sessionid[1]) * 36 + decodesessionchar($sessionid[2]) * 36 * 36; $utmpkey = decodesessionchar($sessionid[3]) + decodesessionchar($sessionid[4]) * 36 + decodesessionchar($sessionid[5]) * 36 * 36 + decodesessionchar($sessionid[6]) * 36 * 36 * 36 + decodesessionchar($sessionid[7]) * 36 * 36 * 36 * 36 + decodesessionchar($sessionid[8]) * 36 * 36 * 36 * 36 * 36; $userid = ''; $compat_telnet = 1; } else { @($utmpkey = $_COOKIE["UTMPKEY"]); @($utmpnum = $_COOKIE["UTMPNUM"]); @($userid = $_COOKIE["UTMPUSERID"]); } if ($utmpkey != "") { if (($ret = bbs_setonlineuser($userid, intval($utmpnum), intval($utmpkey), $currentuinfo_tmp, $compat_telnet)) == 0) { $loginok = 1; $currentuinfo_num = bbs_getcurrentuinfo(); $currentuser_num = bbs_getcurrentuser($currentuser); } else { $utmpkey = ""; } } // add by stiger, 如果登陆失败就继续用guest登陆 if ($utmpkey == "") { $error = bbs_wwwlogin(0); if ($error == 2 || $error == 0) { $data = array(); $num = bbs_getcurrentuinfo($data); setcookie("UTMPKEY", $data["utmpkey"], 0, "/"); setcookie("UTMPNUM", $num, 0, "/"); setcookie("UTMPUSERID", $data["userid"], 0, "/"); setcookie("LOGINTIME", $data["logintime"], 0, "/"); setcookie("WWWPARAMS", WWW_DEFAULT_PARAMS, 0, "/"); @($utmpkey = $data["utmpkey"]); @($utmpnum = $num); @($userid = $data["userid"]); $compat_telnet = 1; } //guest 登陆成功,设置一下 if ($utmpkey != "") { if (($ret = bbs_setonlineuser($userid, intval($utmpnum), intval($utmpkey), $currentuinfo_tmp, $compat_telnet)) == 0) { $loginok = 1; $currentuinfo_num = bbs_getcurrentuinfo(); $currentuser_num = bbs_getcurrentuser($currentuser); } } } $currentuinfo = $currentuinfo_tmp; settype($utmpnum, "integer"); if ($loginok != 1 && $_SERVER["PHP_SELF"] != "/bbslogin.php") { error_nologin(); return; } if ($loginok == 1 && (isset($setboard) && $setboard == 1)) { bbs_set_onboard(0, 0); } //add end }
/** * function initUser check current user cookie data valid * if valid , complete the user init. guest is also a currrent user * * @param string $id * @param int $utmpnum * @param string $utmpkey * @return boolean true|false if cookie data is invalid * @static * @access public */ public static function initUser($id, $utmpnum, $utmpkey, $telnet = false) { $arr = array(); $telnet = $telnet ? 1 : 0; return bbs_setonlineuser($id, $utmpnum, $utmpkey, $arr, $telnet) == 0; }