auth.php 1.3 KB
Newer Older
mattl's avatar
mattl committed
1 2
<?php

mattl's avatar
mattl committed
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
/* Libre.fm -- a free network service for sharing your music listening habits

   Copyright (C) 2009 Libre.fm Project

   This program is free software: you can redistribute it and/or modify
   it under the terms of the GNU Affero General Public License as published by
   the Free Software Foundation, either version 3 of the License, or
   (at your option) any later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU Affero General Public License for more details.

   You should have received a copy of the GNU Affero General Public License
   along with this program.  If not, see <http://www.gnu.org/licenses/>.

*/

elleo's avatar
elleo committed
22
require_once('database.php');
23
require_once('data/User.php');
elleo's avatar
elleo committed
24 25 26

session_start();
if(isset($_SESSION['session_id'])) {
27
	$res = $mdb2->query('SELECT username FROM Scrobble_Sessions WHERE '
28
		. 'sessionid = ' . $mdb2->quote($_SESSION['session_id'], 'text')
29
		. ' AND expires > ' . $mdb2->quote(time(), 'integer'));
30
	if(PEAR::isError ($res) || !$res->numRows()) {
elleo's avatar
elleo committed
31 32 33 34
		// Session is invalid
		unset($_SESSION['session_id']);
	} else {
		$logged_in = true;
35
		$row = $res->fetchRow(MDB2_FETCHMODE_ASSOC);
36
		$u_user = new User($row['username']);
elleo's avatar
elleo committed
37 38 39
	}
}
?>