-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvalidateUserCF.php
66 lines (62 loc) · 1.51 KB
/
validateUserCF.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
<!DOCTYPE HTML>
<html>
<head>
</head>
<body>
<?php
// define variables and set to empty values
$username = $password = "";
if ($_SERVER["REQUEST_METHOD"] == "POST")
{
$username = test_input($_POST["name"]);
$password = test_input($_POST["password"]);
$conn =new mysqli("localhost","root","mishra2014","CrowdFluttr");
// Check connection
if ($conn->connect_error)
{
$result=array("DBConnection"=>0);
print json_encode($result);
//die("Connection failed: " . $conn->connect_error);
}
else
{
$result=array("DBConnection"=>1);
}
$sql="select username from user where username = '$username' and pass = '$password'";
$queryResult=$conn->query($sql);
//echo '<br>'.$queryResult->num_rows;
if($queryResult->num_rows > 0)
{
$result=$result+array("validate"=>1);
}
else
{
$result=$result+array("validate"=>0);
}
print json_encode($result);
$queryResult->close();
$conn->close();
if($result["validate"]==1)
{
session_start();
$_SESSION['username']=$username;
header("Location: http://mishra14.ddns.net/userHomeCF.php");
}
}
function test_input($data) {
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
?>
<h2>CrowdFluttr Peer Evaluation Demo - Login</h2>
<form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">
Name: <input type="text" name="name">
<br><br>
Password: <input type="password" name="password">
<br><br>
<input type="submit" name="submit" value="Submit">
</form>
</body>
</html>