File index.php :
<?php
include "config.php";
?>
<form action="submit.php" method="post">
<label>Username</label>
<input type="text" name="username">
<label>Password</label>
<input type="password" name="password">
<input type="submit" name="submit" value="Submit">
</form>
File config.php:
<?php
session_start();
$host = "localhost";
$username = "root";
$password = "";
$database = "loading";
$con = new mysqli($host, $username, $password, $database);
if($con->connect_error){
die("Connection failed:" . $con->connect_error);
}
?>
File submit.php:
<?php
include "config.php";
$username = $_POST['username'];
$password = $_POST['password'];
if(isset($_POST['submit'])){
$sql = "SELECT * FROM userlogin WHERE username = '".$username."' AND password = '".$password."'";
$result = $con->query($sql);
if($result->num_rows == 1){
$_SESSION['username'] = $username;
$_SESSION['password'] = $password;
header("location: loginform.php");
}else{
echo "credentials not matched";
}
}
?>
<?php
include "config.php";
?>
<form action="submit.php" method="post">
<label>Username</label>
<input type="text" name="username">
<label>Password</label>
<input type="password" name="password">
<input type="submit" name="submit" value="Submit">
</form>
File config.php:
<?php
session_start();
$host = "localhost";
$username = "root";
$password = "";
$database = "loading";
$con = new mysqli($host, $username, $password, $database);
if($con->connect_error){
die("Connection failed:" . $con->connect_error);
}
?>
File submit.php:
<?php
include "config.php";
$username = $_POST['username'];
$password = $_POST['password'];
if(isset($_POST['submit'])){
$sql = "SELECT * FROM userlogin WHERE username = '".$username."' AND password = '".$password."'";
$result = $con->query($sql);
if($result->num_rows == 1){
$_SESSION['username'] = $username;
$_SESSION['password'] = $password;
header("location: loginform.php");
}else{
echo "credentials not matched";
}
}
?>
File loginform.php:
<?php
include 'config.php';
$u = $_SESSION['username'];
echo "Welcome " . $u;
if(isset($_POST['logout_submit'])){
session_destroy();
header('location: index.php');
}
?>
<form action="" method="post">
<input type="submit" name="logout_submit" value="Logout">
</form>
File authentic.php:
<?php
include 'config.php';
$username = $_SESSION['username'];
$password = $_SESSION['password'];
echo "Cridential are - <br/>Username: " . $username . " <br/> Password: " . $password;
if($_SESSION['username'] == '' AND $_SESSION['password'] == ''){
header('location: index.php');
}
if(isset($_POST['logout_submit'])){
session_destroy();
header('location: index.php');
}
?>
<form action="" method="post">
<input type="submit" name="logout_submit" value="Logout">
</form>
No comments:
Post a Comment