-
Notifications
You must be signed in to change notification settings - Fork 0
/
login.php
68 lines (48 loc) · 1.42 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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
<?php
if(isset($_POST['submit'])) {
$errorMessage = "";
$username = $_POST['username'];
$password = $_POST['password'];
if(empty($username)) {
$errorMessage .= "username";
header("location: index.php");
}
if(empty($password)) {
$errorMessage .= "password";
header("location: index.php");
}
if(empty($errorMessage)) {
$db = mysql_connect("localhost","root",""); //connect to database
if(!$db) die("Error connecting to MySQL database.");
mysql_select_db("thenovaleague" ,$db);
$sql = "SELECT * FROM user WHERE username=".
PrepSQL($username) . " AND userpass=" .
PrepSQL($password);
$query = mysql_query($sql);
$rows = mysql_num_rows($query);
if ($rows == 1) {
//initialize cookie
$cookie_name = "user";
$cookie_value = $username;
setcookie($cookie_name, $_COOKIE[$cookie_name] = $cookie_value, time() + (86400 * 30), "/");
header("location: profile.php");
} else {
header("location: index.php");
}
}
}
// function: PrepSQL()
// use stripslashes and mysql_real_escape_string PHP functions
// to sanitize a string for use in an SQL query
// also puts single quotes around the string
//
function PrepSQL($value) {
// Stripslashes
if(get_magic_quotes_gpc()) {
$value = stripslashes($value);
}
// Quote
$value = "'" . mysql_real_escape_string($value) . "'";
return($value);
}
?>