-
Notifications
You must be signed in to change notification settings - Fork 0
/
login.php
48 lines (44 loc) · 1.13 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
<?php
//Start session
session_start();
//Connect to mysql server
require "db.php";
//Function to sanitize values received from the form. Prevents SQL injection
function clean($str) {
$str = @trim($str);
if(get_magic_quotes_gpc()) {
$str = stripslashes($str);
}
return mysqli_real_escape_string($str);
}
//Sanitize the POST values
$login = ($_POST['username']);
$password = ($_POST['password']);
//Create query
$qry="SELECT * FROM admin WHERE username='$login' AND password='$password'";
$result=mysqli_query($conn,$qry);
//while($row = mysqli_fetch_array($result))
// {
// $level=$row['position'];
// }
//Check whether the query was successful or not
if($result) {
if(mysqli_num_rows($result) > 0) {
//Login Successful
session_regenerate_id();
$member = mysqli_fetch_assoc($result);
$_SESSION['SESS_MEMBER_ID'] = $member['id'];
$_SESSION['SESS_FIRST_NAME'] = $member['username'];
session_write_close();
//if ($level="admin"){
header("location: admin/dashboard.php");
exit();
}else {
//Login failed
header("location: index.php");
exit();
}
}else {
die("Query failed");
}
?>