예제 #1
0
 public static function testSession($session_id)
 {
     //returns user id, dies absolutely if session is invalid
     $prfx = DB_PREFIX;
     //test session ID to have only alphanumeric characters
     $session_regexp = "^[a-zA-Z0-9_]+\$";
     if (!ereg($session_regexp, $session_id)) {
         throwBusinessLogicError(3);
     }
     //test if there is at least one such user
     $user_row = Data::getRow("SELECT {$prfx}user.*, {$prfx}contest.settings\r\n       FROM {$prfx}session\r\n       INNER JOIN {$prfx}user\r\n       ON {$prfx}session.user_id={$prfx}user.id\r\n       LEFT JOIN {$prfx}contest\r\n       ON {$prfx}user.contest_id={$prfx}contest.id\r\n       WHERE session_id='{$session_id}'");
     if (!$user_row) {
         throwBusinessLogicError(3);
     }
     if (is_null($user_row['settings'])) {
         $user_row['settings'] = serialize(null);
     }
     RequestUtils::$user_row = $user_row;
     //return found user
     return $user_row;
 }