In this video, today you are going to learn how to create a login and logout system easily for a web-based system using PHP, MySql, HTML. First, you need to Install a localhost server(eg:- XAMPP, WampServer) to your pc. Then go to the htdocs file in the localhost server. Then create a new folder inside the htdocs name login(you can use any name for this folder). Then you need to create those files “database connenction.php”, “home.php”, “login.php”, and “logout process.php” inside that login folder. Now files are ready.

Subscribe: https://www.youtube.com/channel/UCNDmzGYwwT3rdY3xQuW8QOA

Source codes:

login.php


<!--<!DOCTYPE html>
<html>
<head>
    <title>Login page</title>
</head>
<body>

<center>

    <p>Login</p>

<form action="login process.php" method="POST">

    <input type="text" id="user" name="username" placeholder="username"/><br><br>
    <input type="text" id="pass" name="password" placeholder="password"/><br><br>
    <button type="submit" id="btn" name="login" default>login</button>

</form>

</center>

</body>
</html>-->

home.php


<!--<?php session_start();
if(empty($_SESSION['id'])):
    header('Location:login.php');
endif;
?>

<!DOCTYPE html>
<html>
<head>
    <title>Home page</title>
</head>
<body>

    <a href="logout process.php"><div style="float:right"><button>logout</button></div></a>

    <h1>Welcome to home page...!</h1>

</body>
</html>-->

database connection.php


<?php
$con = mysqli_connect("localhost","root","","login_db");

// Check connection
if (mysqli_connect_errno())
  {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
  }
?>

login process.php



<!--<?php session_start();

include('database connection.php');

if(isset($_POST['login']));
{
    $user_unsafe=$_POST['username'];
    $pass_unsafe=$_POST['password'];

    $user = mysqli_real_escape_string($con,$user_unsafe);
    $pass = mysqli_real_escape_string($con,$pass_unsafe);

    $query=mysqli_query($con,"select * from login where username='$user' and password='$pass'")or die(mysqli_error($con));

    $row=mysqli_fetch_array($query);

         $name=$row['username'];
         $counter=mysqli_num_rows($query);
         $id=$row['id'];

         if ($counter == 0)
         {
            echo "<script type='text/javascript'>alert('Invalid Usrename or Password!');
            document.location='login.php'</script>";
         }
         else
         {
            $_SESSION['id']=$id;
            $_SESSION['username']=$name;

            echo "<script type='text/javascript'>document.location='home.php'</script>";
         }

}

?>-->

logout process.php


<!--<?php session_start();
if(empty($_SESSION['id'])):
    header('Location:login.php');
endif;
?>
<!DOCTYPE html>
<html>
<body>
    <div style="width:150px;margin:auto;height:500px;margin-top:300px">

    <?php
     include('database connection.php');
     session_destroy();

     echo '<meta http-equiv="refresh" content="2;url=login.php">';
     echo '<progress max=100><strong>Progress: 60% done.</strong></progress><br>';
     echo '<span class="itext">Logging out please wait!...</span>';

    ?>
    </div>

</body>
</html>-->

#php #mysql #javascript

Create a Login and Logout easily for a Web-Base System Using PHP, MySql, HTML
6.20 GEEK