0% found this document useful (0 votes)
28 views16 pages

Project Work and Coding

This PHP code handles user login authentication. It checks submitted username and password credentials against a database. If the credentials match a user record, it stores the username in a session variable and redirects to the index page. Otherwise, it displays an error message. The code also includes options to register a new user and logout by destroying the session.

Uploaded by

kvsingh7890
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
28 views16 pages

Project Work and Coding

This PHP code handles user login authentication. It checks submitted username and password credentials against a database. If the credentials match a user record, it stores the username in a session variable and redirects to the index page. Otherwise, it displays an error message. The code also includes options to register a new user and logout by destroying the session.

Uploaded by

kvsingh7890
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 16

<?

php

include("db.php");

session_start();

if ($_SERVER["REQUEST_METHOD"] == "POST") {

$email = $_POST['email'];

$password = $_POST['password'];

$sql = "SELECT * FROM users WHERE email='$email' AND


password='$password'";

$result = $conn->query($sql);

if ($result->num_rows > 0) {

// Fetch the username from the result set

$row = $result->fetch_assoc();

// echo $row;

$username = $row['username'];

// Store the username in the session variable

$_SESSION['username'] = $username;

// Redirect to index.php
header("Location: index.php");

exit;

} else {

echo "Invalid username or password";

$conn->close();

?>

<!DOCTYPE html>

<html lang="en">

<head>

<meta charset="UTF-8">

<meta name="viewport" content="width=device-width, initial-


scale=1.0">

<title>Attendance App</title>

<link rel="icon" href="th.jpg" type="image/x-icon">

<!-- bootstap -->

<link
href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootst
rap.min.css" rel="stylesheet" integrity="sha384-
QWTKZyjpPEjISv5WaRU9OFeRpok6YctnYmDr5pNlyT2bRjXh0JMhjY6h
W+ALEwIH" crossorigin="anonymous">

<link rel="stylesheet"
href="https://cdnjs.cloudflare.com/ajax/libs/toastr.js/latest/css/toas
tr.min.css">

<style>

*{

-webkit-box-sizing: border-box;

-moz-box-sizing: border-box;

box-sizing: border-box;

.card{

margin-left: 25%;

margin-top: 8%;

.buttons {

margin: 10%;

text-align: center;

.btn-hover {
width: 200px;

font-size: 16px;

font-weight: 600;

color: #fff;

cursor: pointer;

height: 55px;

text-align:center;

border: none;

background-size: 300% 100%;

border-radius: 10px;

-moz-transition: all .4s ease-in-out;

-o-transition: all .4s ease-in-out;

-webkit-transition: all .4s ease-in-out;

transition: all .4s ease-in-out;

.btn-hover:hover {

background-position: 100% 0;

-moz-transition: all .4s ease-in-out;

-o-transition: all .4s ease-in-out;


-webkit-transition: all .4s ease-in-out;

transition: all .4s ease-in-out;

.btn-hover:focus {

outline: none;

.btn-hover.color-1 {

background-image: linear-gradient(to right, #25aae1, #40e495,


#30dd8a, #2bb673);

box-shadow: 0 4px 15px 0 rgba(49, 196, 190, 0.75);

</style>

</head>

<body class="bg-dark">

<div class="container ">

<div class="row">

<div class="card col-md-5">

<div>img=th.jpg</div>

<h2 class="text-center text-success mt-3 p-2">Login


here</h2>

<?php
if(isset($_GET['status']) && $_GET['status'] == 'success') {

echo '<p class="alert alert-success">User Registered


successfully!</p>';

?>

<form class="mt-3 " action="<?php echo


htmlspecialchars($_SERVER["PHP_SELF"]); ?>" method="post">

<!-- Password input -->

<div data-mdb-input-init class="form-outline mb-4">

<label class="form-label"
for="form2Example2">Email</label>

<input type="text" name="email" id="max" class="form-


control" />

</div>

<!-- Password input -->

<div class="form-outline mb-4">

<label class="form-label"
for="form2Example2">Password</label>

<input type="password" name="password"


id="attended" class="form-control" />

</div>
<p>

Wanna do Sign Up? <a href="register.php">SignUp</a>

</p>

<!-- Submit button -->

<button data-mdb-ripple-init type="submit" class="color-


1 btn-hover w-100 mb-4">Login</button>

<!-- Register buttons -->

</form>

</div>

</div>

</div>

<!-- tostr -->

<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>

<script
src="http://cdnjs.cloudflare.com/ajax/libs/toastr.js/latest/js/toastr.
min.js"></script>

</body>

</html>
<?php

session_start();

// Unset all of the session variables

$_SESSION = array();

// Destroy the session.

session_destroy();

// Redirect to login page

header("Location: login.php");

exit;

?>

You might also like