+
+ // Init global user data array
+ initUserData();
+
+ // Fix "deleted" cookies first
+ fixDeletedCookies(array('userid', 'u_hash'));
+
+ // Are cookies set?
+ if ((isUserIdSet()) && (isSessionVariableSet('u_hash'))) {
+ // Cookies are set with values, but are they valid?
+ if (fetchUserData(getUserId()) === true) {
+ // Validate password by created the difference of it and the secret key
+ $valPass = generatePassString(getUserData('password'));
+
+ // Transfer last module and online time
+ $GLOBALS['last_online']['module'] = getUserData('last_module');
+ $GLOBALS['last_online']['online'] = getUserData('last_online');
+
+ // So did we now have valid data and an unlocked user?
+ if ((getUserData('status') == 'CONFIRMED') && ($valPass == getSession('u_hash'))) {
+ // Account is confirmed and all cookie data is valid so he is definely logged in! :-)
+ $ret = true;
+ } else {
+ // Maybe got locked etc.
+ //* DEBUG: */ print(__LINE__."!!!<br />");
+ destroyUserSession();
+ }
+ } else {
+ // Cookie data is invalid!
+ //* DEBUG: */ print(__LINE__."***<br />");
+ destroyUserSession();
+ }
+ } else {
+ // Cookie data is invalid!
+ //* DEBUG: */ print(__LINE__."///<br />");
+ destroyUserSession();
+ }
+
+ // Cache status
+ $GLOBALS['is_member'] = $ret;
+
+ // Return status
+ return $ret;
+}
+
+// Fetch user data for given user id
+function fetchUserData ($userid, $column='userid') {
+ // Don't look for invalid userids...
+ if ($userid < 1) {
+ // Invalid, so abort here
+ debug_report_bug('User id ' . $userid . ' is invalid.');
+ } elseif (isset($GLOBALS['user_data'][$userid])) {
+ // Use cache, so it is fine
+ return true;
+ }
+
+ // By default none was found
+ $found = false;
+
+ // Do we have userid/refid?
+ if (($column == 'userid') || ($column == 'refid')) {
+ // Then secure the id
+ $userid = bigintval($userid);
+ } // END - if
+
+ // Query for the user
+ $result = SQL_QUERY_ESC("SELECT * FROM `{?_MYSQL_PREFIX?}_user_data` WHERE `%s`='%s' LIMIT 1",
+ array($column, $userid), __FUNCTION__, __LINE__);
+
+ // Do we have a record?
+ if (SQL_NUMROWS($result) == 1) {
+ // Load data from cookies
+ $data = SQL_FETCHARRAY($result);
+
+ // Set the userid for later use
+ setCurrentUserId($data['userid']);
+ $GLOBALS['user_data'][getCurrentUserId()] = $data;
+
+ // Rewrite 'last_failure' if found
+ if (isset($GLOBALS['user_data'][getCurrentUserId()]['last_failure'])) {
+ // Backup the raw one and zero it
+ $GLOBALS['user_data'][getCurrentUserId()]['last_failure_raw'] = $GLOBALS['user_data'][getCurrentUserId()]['last_failure'];
+ $GLOBALS['user_data'][getCurrentUserId()]['last_failure'] = 0;
+
+ // Is it not zero?
+ if ($GLOBALS['user_data'][getCurrentUserId()]['last_failure_raw'] != '0000-00-00 00:00:00') {
+ // Seperate data/time
+ $array = explode(' ', $GLOBALS['user_data'][getCurrentUserId()]['last_failure']);
+
+ // Seperate data and time again
+ $array['date'] = explode('-', $array[0]);
+ $array['time'] = explode(':', $array[1]);
+
+ // Now pass it to mktime()
+ $GLOBALS['user_data'][getCurrentUserId()]['last_failure'] = mktime(
+ $array['time'][0],
+ $array['time'][1],
+ $array['time'][2],
+ $array['date'][1],
+ $array['date'][2],
+ $array['date'][0]
+ );
+ } // END - if
+ } // END - if
+
+ // Found, but valid?
+ $found = isUserDataValid();
+ } // END - if
+
+ // Free memory
+ SQL_FREERESULT($result);
+
+ // Return result
+ return $found;