Skip to content

Instantly share code, notes, and snippets.

@biplab3
Last active July 20, 2020 09:30
Show Gist options
  • Save biplab3/4613e923b1b363e96e73289ba61f4afb to your computer and use it in GitHub Desktop.
Save biplab3/4613e923b1b363e96e73289ba61f4afb to your computer and use it in GitHub Desktop.
<?php
include '../connect.php';
session_start();
if(isset($_POST['login'])){
$username = $_POST['username'];
$password = $_POST['password'];
//check login details
$stmt = $con->prepare("select * from users where username = '$username' and password = '$password'");
$stmt->execute();
//echo $stmt->rowCount();
//exit();
if($stmt->rowCount()>0){
$_SESSION['username'] = $username;
header("location: home.php");
$_SESSION['success'] = "You are logged in";
}
else{
header("location: login.php");
$_SESSION['error'] = "<div class='alert alert-danger' role='alert'>Oh snap! Invalid login details.</div>";
}
}
?>
<html>
<head>
<title>session example</title>
<link rel="stylesheet" href="../bootstrap.css" crossorigin="anonymous">
<!-- Optional theme -->
<link rel="stylesheet" href="../bootstrap-theme.css" crossorigin="anonymous">
<style>
.container{
width:50%;
height:30%;
padding:20px;
}
</style>
</head>
<body>
<div class="container">
<h3 align="center"><u>Login Form</u></h3>
<br/><br/><br/><br/>
<?php if(isset($_SESSION['error'])){ echo $_SESSION['error']; }?>
<form action="" method="post" class="form-horizontal">
<div class="form-group">
<label class="control-label col-sm-2" for="email">Username*:</label>
<div class="col-sm-10">
<input type="text" class="form-control" name="username" placeholder="Please enter the Username">
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-2" for="phone">Password*:</label>
<div class="col-sm-10">
<input type="password" class="form-control" name="password" placeholder="Please enter the password">
</div>
</div>
<br/><br/>
<button type="submit" class="btn btn-info btn-block" name="login">Submit</button>
</form>
</div>
<script src="../jquery-3.2.1.min.js"></script>
<script src="../bootstrap.min.js"></script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment