function loadUserSettings()
{
global $modSettings, $user_settings;
global $ID_MEMBER, $db_prefix, $cookiename, $user_info, $language;
// Check first the integration, then the cookie, and last the session.
if (isset($modSettings['integrate_verify_user']) && function_exists($modSettings['integrate_verify_user']))
{
$ID_MEMBER = (int) call_user_func($modSettings['integrate_verify_user']);
$already_verified = $ID_MEMBER > 0;
}
else
$ID_MEMBER = 0;
if (empty($ID_MEMBER) && isset($_COOKIE[$cookiename]))
{
$_COOKIE[$cookiename] = stripslashes($_COOKIE[$cookiename]);
// Fix a security hole in PHP 4.3.9 and below...
if (preg_match('~^a:[34]:\{i:0;(i:\d{1,6}|s:[1-8]:"\d{1,8}");i:1;s:(0|40):"([a-fA-F0-9]{40})?";i:2;[id]:\d{1,14};(i:3;i:\d;)?\}$~', $_COOKIE[$cookiename]) == 1)
{
list ($ID_MEMBER, $password) = @unserialize($_COOKIE[$cookiename]);
$ID_MEMBER = !empty($ID_MEMBER) && strlen($password) > 0 ? (int) $ID_MEMBER : 0;
}
else
$ID_MEMBER = 0;
}
elseif (empty($ID_MEMBER) && isset($_SESSION['login_' . $cookiename]) && ($_SESSION['USER_AGENT'] == $_SERVER['HTTP_USER_AGENT'] || !empty($modSettings['disableCheckUA'])))
{
// !!! Perhaps we can do some more checking on this, such as on the first octet of the IP?
list ($ID_MEMBER, $password, $login_span) = @unserialize(stripslashes($_SESSION['login_' . $cookiename]));
$ID_MEMBER = !empty($ID_MEMBER) && strlen($password) == 40 && $login_span > time() ? (int) $ID_MEMBER : 0;
}
// Only load this stuff if the user isn't a guest.
if ($ID_MEMBER != 0)
{
// Is the member data cached?
if (empty($modSettings['cache_enable']) || $modSettings['cache_enable'] < 2 || ($user_settings = cache_get_data('user_settings-' . $ID_MEMBER, 60)) == null)
{
$request = db_query("
SELECT mem.*, IFNULL(a.ID_ATTACH, 0) AS ID_ATTACH, a.filename, a.attachmentType
FROM {$db_prefix}members AS mem
LEFT JOIN {$db_prefix}attachments AS a ON (a.ID_MEMBER = $ID_MEMBER)
WHERE mem.ID_MEMBER = $ID_MEMBER
LIMIT 1", __FILE__, __LINE__);
$user_settings = mysql_fetch_assoc($request);
mysql_free_result($request);
if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2)
cache_put_data('user_settings-' . $ID_MEMBER, $user_settings, 60);
}
// Did we find 'im? If not, junk it.
if (!empty($user_settings))
{
// As much as the password should be right, we can assume the integration set things up.
if (!empty($already_verified) && $already_verified === true)
$check = true;
// SHA-1 passwords should be 40 characters long.
elseif (strlen($password) == 40)
$check = sha1($user_settings['passwd'] . $user_settings['passwordSalt']) == $password;
else
$check = false;
// Wrong password or not activated - either way, you're going nowhere.
$ID_MEMBER = $check && ($user_settings['is_activated'] == 1 || $user_settings['is_activated'] == 11) ? $user_settings['ID_MEMBER'] : 0;
}
else
$ID_MEMBER = 0;
}