-
Notifications
You must be signed in to change notification settings - Fork 0
/
login.php
65 lines (57 loc) · 2.04 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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Login</title>
</head>
<body>
<?php
$flag=1;
require 'connect.inc.php';
session_start();
// If form submitted, insert values into the database.
if (isset($_POST['submit'])&&!empty($_POST['submit'])){
$username = stripslashes($_POST['username']); // removes backslashes
$username = mysqli_real_escape_string($link,$username); //escapes special characters in a string
$password = stripslashes($_POST['password']);
$password = mysqli_real_escape_string($link,$password);
//Checking is user existing in the database or not
$query = "SELECT COUNT(`id`) FROM `users` WHERE username='$username' and password='".md5($password)."'";
//echo $query.'<br />';
$query_run = mysqli_query($link,$query) or die(connection_status());
//$rows = mysqli_num_rows($result);
//echo $rows;
if($query_run==true){
//if(mysqli_affected_rows($link)===1){
$_SESSION['username'] = $username;
$flag=0;
/*$_SESSION['username'] = $username;
$sql="SELECT `user_id` from `users` WHERE username='$username' and password='".md5($password)."'" ;
$sql1=mysqli_query($link,$sql);
while($row=mysqli_fetch_assoc($sql1)){
$_SESSION['id']=$row['user_id'];
}
*/
header("Location:homepage.php"); // Redirect user to index.php
}else{
echo "Username/password is incorrect";
$flag=1;
}
}
if($flag){
?>
<h1>Log In</h1>
<div>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" name="login">
<input type="text" name="username" placeholder="Username" value="<?php if(!empty($_POST['username'])) echo $_POST['username']; ?>" required /><br /><br />
<input type="password" name="password" placeholder="Password" value="<?php if(!empty($_POST['password'])) echo $_POST['password']; ?>" required /><br /><br /><br />
<input name="submit" type="submit" value="Login" />
</form>
<p>Not registered yet? <a href='register.php'>Register Here</a></p>
<br /><br />
</div>
<?php
}
?>
</body>
</html>