<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Login</title>
<link rel="stylesheet" href="style.css" />
</head>
<body>
<?php
require('databaseConnect.php');
session_start();
if (isset($_POST['username'])) {
$username = $_POST['username'];
$password = $_POST['password'];
$query = "SELECT * FROM `UserReg` WHERE username='$username' and password='" . md5($password) . "'";
$result = mysql_query($query) or die(mysql_error());
$rows = mysql_num_rows($result);
if($rows==1){
$_SESSION['username'] = $username;
if($admin == 1) { // here $role should be database value whatever you have taken
//redirect page for admin
}else
header("Location: admin.php"); // This will redirect the user to index.php page.
}else{
echo "<div class='form'><h3>Username/password is incorrect.</h3><br/>Click here to <a href='login.php'>Login</a></div>";
}
function test_input($data)
{
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
?>
<div class="testbox">
<img src="Logo.png" alt="Logo" align="middle" style="width:340px;height:90px;" >
<h1>Login</h1>
<form action="<?php
echo htmlspecialchars($_SERVER["PHP_SELF"]);
?>" method="post" name="login">
<label id="icon" for="name"><i class="icon-user"></i></label>
<input type="text" name="username" id="name" placeholder="Username" required/>
<label id="icon" for="name"><i class="icon-shield"></i></label>
<input type="password" name="password" id="name" placeholder="Password" required/>
<input name="submit" type="submit" value="Login" />
<input type="reset" value="Reset"/>
<a href='registration.php'>Register Here</a>
</form>
</div>
<?php
}
?>
</body>
</html>
- A user can login perfectly fine.
- In the database i have assigned the users to 0 and the admin to 1.
- What do i need to add to the code to allow the admin to login and be directed to a different page, other than the index page.