diff options
author | nikrou <nikrou@piwigo.org> | 2006-07-23 15:25:49 +0000 |
---|---|---|
committer | nikrou <nikrou@piwigo.org> | 2006-07-23 15:25:49 +0000 |
commit | 5d06d4354144066a39bca1c28b7a326b2de5283c (patch) | |
tree | a3ececb0721ce8bc367b9bc05dc03af0cfe1f68f /include/functions_user.inc.php | |
parent | e3c4d79f5be8d732185c151f9ac84ff0ddb51166 (diff) |
bug 451 fixed: problem with auto login
- add an auto_login_key in users_table
- $conf['session_length'] is no more useful
and sessions length will be 0 (until browser closed)
- add $conf['remember_me_name'] for cookie remember name
git-svn-id: http://piwigo.org/svn/trunk@1493 68402e56-0260-453c-a942-63ccdbb3a9ee
Diffstat (limited to '')
-rw-r--r-- | include/functions_user.inc.php | 28 |
1 files changed, 25 insertions, 3 deletions
diff --git a/include/functions_user.inc.php b/include/functions_user.inc.php index c3048d6b0..134f7493d 100644 --- a/include/functions_user.inc.php +++ b/include/functions_user.inc.php @@ -551,12 +551,34 @@ function get_language_filepath($filename) function log_user($user_id, $remember_me) { global $conf; - $session_length = $conf['session_length']; + if ($remember_me) { - $session_length = $conf['remember_me_length']; + // search for an existing auto_login_key + $query = ' +SELECT auto_login_key + FROM '.USERS_TABLE.' + WHERE '.$conf['user_fields']['id'].' = '.$user_id.' +;'; + + $auto_login_key = current(mysql_fetch_assoc(pwg_query($query))); + if (empty($auto_login_key)) + { + $auto_login_key = base64_encode(md5(uniqid(rand(), true))); + $query = ' +UPDATE '.USERS_TABLE.' + SET auto_login_key=\''.$auto_login_key.'\' + WHERE '.$conf['user_fields']['id'].' = '.$user_id.' +;'; + pwg_query($query); + } + $cookie = array('id' => $user_id, 'key' => $auto_login_key); + setcookie($conf['remember_me_name'], + serialize($cookie), + time()+$conf['remember_me_length'], + cookie_path() + ); } - session_set_cookie_params($session_length); session_start(); $_SESSION['pwg_uid'] = $user_id; } |