From 60a43519b9c1a66265d5374dec98bf0dae7095db Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Tue, 9 Dec 2008 12:54:46 -0500 Subject: [PATCH] slightly better reporting when setting rememberme cookies darcs-hash:20081209175446-84dde-ae63433fa42debe8fb2eb3862cac0b9f81f1e6de.gz --- lib/util.php | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/lib/util.php b/lib/util.php index 2484ae6b6d..87a6a42c56 100644 --- a/lib/util.php +++ b/lib/util.php @@ -602,7 +602,7 @@ function common_set_cookie($key, $value, $expiration=0) { } define('REMEMBERME', 'rememberme'); -define('REMEMBERME_EXPIRY', 30 * 24 * 60 * 60); +define('REMEMBERME_EXPIRY', 30 * 24 * 60 * 60); # 30 days function common_rememberme($user=NULL) { if (!$user) { @@ -612,19 +612,26 @@ function common_rememberme($user=NULL) { return false; } } + $rm = new Remember_me(); $rm->code = common_good_rand(16); $rm->user_id = $user->id; $result = $rm->insert(); + if (!$result) { common_log_db_error($rm, 'INSERT', __FILE__); common_debug('Error adding rememberme record for ' . $user->nickname, __FILE__); return false; - } - common_log(LOG_INFO, 'adding rememberme cookie for ' . $user->nickname); - common_set_cookie(REMEMBERME, - implode(':', array($rm->user_id, $rm->code)), - time() + REMEMBERME_EXPIRY); + } + + common_debug('Inserted rememberme record (' . $rm->code . ', ' . $rm->user_id . '); result = ' . $result . '.', __FILE__); + + $cookieval = $rm->user_id . ':' . $rm->code; + + common_log(LOG_INFO, 'adding rememberme cookie "' . $cookieval . '" for ' . $user->nickname); + + common_set_cookie(REMEMBERME, $cookieval, time() + REMEMBERME_EXPIRY); + return true; }