Login.html
<html>
<head>
<title>User Login</title>
<link rel="stylesheet" type="text/css" href="styles.css" />
</head>
<body>
<form name="frmUser" method="POST" action="login.php">
<div class="message"><?php if($message!="") { echo $message; } ?></div>
<table border="0" cellpadding="10" cellspacing="1" width="500" align="center">
<tr class="tableheader">
<td align="center" colspan="2">Enter Login Details</td>
</tr>
<tr class="tablerow">
<td align="right">Username</td>
<td><input type="text" name="userName"></td>
</tr>
<tr class="tablerow">
<td align="right">Password</td>
<td><input type="password" name="password"></td>
</tr>
<tr class="tableheader">
<td align="center" colspan="2"><input type="submit" name="submit" value="Submit"></td>
</tr>
</table>
</form>
</body>
</html>
login.php
<?php
session_start();
$message="";
if(count($_POST)>0)
{
$con=mysqli_connect("localhost", "root", "", "mydatabase");
$sql="SELECT UserId,UserName,Password FROM loginuser WHERE UserName='" .$_POST["userName"]. "' and Password = '".$_POST["password"]."'";
$result = mysqli_query($con, $sql);
$row = mysqli_fetch_array($result);
if(is_array($row))
{
$_SESSION["userid"] = $row[UserId];
$_SESSION["username"] = $row[UserName];
$_SESSION["password"] = $row[Password];
}
else
{
$message = "Invalid Username or Password!";
}
}
if(isset($_SESSION["username"]))
{
header("Location:user_dashboard.php");
}
?>
style.css
.tableheader {
background-color: #95BEE6;
color:white;
font-weight:bold;
}
.tablerow {
background-color: #A7D6F1;
color:white;
}
.message {
color: #FF0000;
font-weight: bold;
text-align: center;
width: 100%;
}
logout.php
<?php
session_start();
unset($_SESSION["userid"]);
unset($_SESSION["username"]);
header("Location:Login.html");
?>
user_dashboard.php
<?php
session_start();
?>
<html>
<head>
<title>User Login</title>
<link rel="stylesheet" type="text/css" href="styles.css" />
</head>
<body>
<table border="0" cellpadding="10" cellspacing="1" width="500" align="center">
<tr class="tableheader">
<td align="center">User Dashboard</td>
</tr>
<tr class="tablerow">
<td>
<?php
if($_SESSION["username"])
{
?>
Welcome <?php echo $_SESSION["username"]; ?>.</br></br>
Click here to <a href="logout.php" tite="Logout">Logout.
<?php
}
?>
</td>
</tr>
</body>
</html>
https://www.youtube.com/channel/UCKLRUr6U5OFeu7FLOpQ-FSw/videos
<html>
<head>
<title>User Login</title>
<link rel="stylesheet" type="text/css" href="styles.css" />
</head>
<body>
<form name="frmUser" method="POST" action="login.php">
<div class="message"><?php if($message!="") { echo $message; } ?></div>
<table border="0" cellpadding="10" cellspacing="1" width="500" align="center">
<tr class="tableheader">
<td align="center" colspan="2">Enter Login Details</td>
</tr>
<tr class="tablerow">
<td align="right">Username</td>
<td><input type="text" name="userName"></td>
</tr>
<tr class="tablerow">
<td align="right">Password</td>
<td><input type="password" name="password"></td>
</tr>
<tr class="tableheader">
<td align="center" colspan="2"><input type="submit" name="submit" value="Submit"></td>
</tr>
</table>
</form>
</body>
</html>
login.php
<?php
session_start();
$message="";
if(count($_POST)>0)
{
$con=mysqli_connect("localhost", "root", "", "mydatabase");
$sql="SELECT UserId,UserName,Password FROM loginuser WHERE UserName='" .$_POST["userName"]. "' and Password = '".$_POST["password"]."'";
$result = mysqli_query($con, $sql);
$row = mysqli_fetch_array($result);
if(is_array($row))
{
$_SESSION["userid"] = $row[UserId];
$_SESSION["username"] = $row[UserName];
$_SESSION["password"] = $row[Password];
}
else
{
$message = "Invalid Username or Password!";
}
}
if(isset($_SESSION["username"]))
{
header("Location:user_dashboard.php");
}
?>
style.css
.tableheader {
background-color: #95BEE6;
color:white;
font-weight:bold;
}
.tablerow {
background-color: #A7D6F1;
color:white;
}
.message {
color: #FF0000;
font-weight: bold;
text-align: center;
width: 100%;
}
logout.php
<?php
session_start();
unset($_SESSION["userid"]);
unset($_SESSION["username"]);
header("Location:Login.html");
?>
user_dashboard.php
<?php
session_start();
?>
<html>
<head>
<title>User Login</title>
<link rel="stylesheet" type="text/css" href="styles.css" />
</head>
<body>
<table border="0" cellpadding="10" cellspacing="1" width="500" align="center">
<tr class="tableheader">
<td align="center">User Dashboard</td>
</tr>
<tr class="tablerow">
<td>
<?php
if($_SESSION["username"])
{
?>
Welcome <?php echo $_SESSION["username"]; ?>.</br></br>
Click here to <a href="logout.php" tite="Logout">Logout.
<?php
}
?>
</td>
</tr>
</body>
</html>
https://www.youtube.com/channel/UCKLRUr6U5OFeu7FLOpQ-FSw/videos
0 comments
Post a Comment