/
login_func.php
55 lines (44 loc) · 1.26 KB
/
login_func.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
<?php
session_start();
include("extra/database_info.php");
function val ($input) {
if($input == "") {
?>
<script>
alert("sorry but you have not fulled all of the inputs");
document.location = "index.php";
</script>
<?php
}
$input = trim($input);
$input = stripslashes($input);
$input = htmlspecialchars($input);
return $input;
}
$username = val($_POST['user_name']);
$password = val($_POST['user_password']);
$sql = "SELECT password, id FROM user WHERE user_name = '$username'";
$result = mysqli_query($conn, $sql);
if (mysqli_num_rows($result) > 0) {
while($row = mysqli_fetch_assoc($result)){
if (password_verify($password, $row['password'])) {
$_SESSION['id'] = $row['id'];
header("Location: dash.php");
} else {
?>
<script>
alert("Sorry, you Password is wrong, or did not mactch your username");
document.location = "index.php";
</script>
<?php
}
}
} else {
?>
<script>
alert("Sorry your account could not be found");
document.location = "index.php";
</script>
<?php
}
?>