/
login.php
42 lines (33 loc) · 1.01 KB
/
login.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
<?php
/**
@file login.php
@author Licker Nandor
@brief Login handling
*/
include 'include/lang.php';
include 'include/config.php';
include 'include/usr.class.php';
include 'include/db.php';
@session_start ();
if (!isset ($_POST['user']) || !isset ($_POST['pass']) || !isset($_POST['rem'])) {
echo "0";
exit ();
}
$user = mysql_real_escape_string ($_POST['user']);
$pass = mysql_real_escape_string ($_POST['pass']);
$rem = mysql_real_escape_string ($_POST['rem']);
//Check if the user exists and the right password was given
$usr_db = mysql_get ("SELECT * FROM user WHERE `name` = '$user' AND `pass` = '$pass'");
if ($usr_db == FALSE) {
echo "1";
exit ();
}
$_SESSION['usr'] = $usr_db['id'];
$usr = new User ($usr_db);
//Set the cookies if necessary
if ($rem == "true") {
setCookie ("userName", $usr->name, time() + 3600000);
setCookie ("userPass", $usr->pass, time() + 3600000);
}
echo $usr->toJSON ();
?>