Repository navigation
Expand file tree
/
Copy pathindex.php
More file actions
66 lines (45 loc) · 1.4 KB
/
Copy pathindex.php
File metadata and controls
66 lines (45 loc) · 1.4 KB
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
<?php
// start session
session_start();
require_once ("functions.php");
// Send a raw HTTP header with the media type
header("Content-Type: text/html;charset=utf-8");
if($_SERVER["REQUEST_METHOD"]=="POST")
{
$login = $_POST['login'];
$passw = md5($_POST['pass']);
$_SESSION['login'] = $login;
$_SESSION['passw'] = $passw;
// Create connection
$conn = ConnectToServer();
// connect to database
mysqli_query($conn, "use vr2m");
// query type of the user
$sql = "SELECT Usertype FROM LOGIN_USER WHERE Username = '" . $login . "' and Password = '" . $passw . "'";
$result = mysqli_query($conn, $sql);
$row = mysqli_fetch_assoc($result);
$_SESSION['Usertype'] = $row["Usertype"];
if (mysqli_num_rows($result) > 0)
{
if ($row["Usertype"] == 'T')
header('Location: teacher.php');
if ($row["Usertype"] == 'S')
header('Location: student.php');
}
else
echo "Login or Password is wrong";
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="ru" lang="ru">
<body>
<h1>Database project</h1>
<!-- form with login and password -->
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
login<br/> <input type="text" name="login" /><br/>
password<br/> <input type="text" name="pass" /><br/>
<br />
<input type="submit" value="Enter" />
</form>
</body>
</html>