TechSupportNepTechSupportNep - Programming & Tech

  • Home
  • C#.NET
  • PHP
  • JAVA
  • Python
  • ASP.NET
  • VB.NET
  • Android
  • C
  • Tech
    • Tech News
  • Patreoner
TechSupportNep
  • Home
  • Programming
  • PHP
  • How to Create Login Attempt Limit Form in PHP using MySQL Database?
PHP

How to Create Login Attempt Limit Form in PHP using MySQL Database?

By Er. Ran Bahadur B.K. Last updated Aug 15, 2021
3 2,006
Share

In this tutorial, we are going to discuss about how we can limit the user access in login page using PHP and MySQL Database.

In many practical application we need to grand access to the user, if they enter correct username and password. In case, if they forget their credentials(username and password) we need to give them chance to login to their account up to number of times generally three times is given. Beyond that we need to build such a system which does not accept user input. So, this is far more reliable method because many times login attempt may causes the application crash and also an unauthorized person can try many times to get access to the user system. So that it is mandatory to limit the login form/window of an application.

STEPS:

1. If you guyz are working with the PHP for the very first time, then you should know that PHP is server side scripting language, so it executes only in the server. if you create PHP file in your computer and try to run in any browser, there is no output. So working with PHP is far more Different than working in the plain HTML. That’s why you need to install server application in your computer like wamp server, xampp server etc for window.

Download wamp server from here: CLICK HERE

Now you should have text editing software in your PC, every window based PC have Notepad but i am using Dreamweaver CC. After downloading and installing these two software(Dreamweaver and wamp server) you need to define site and testing server in Dreamweaver cc so that every time when you try to execute PHP file, you do not need to save your PHP file by browsing the location of the server. if you don’t know how to do this. Read this article: CLICK HERE

2. After installing wamp server application, Start your wampserver, then open your localhost, for this open up your any browsing software and type localhost or 127.0.0.1 in the address bar. Then new page will appear then scroll down and find phpmyadmin and click on that. Then you will be able to see the login page. Login in by entering username and password (Default username is root and password is empty).

And then click on new and create one database having any name you want and the click OK, then create table having two field in and click on go. After that, you need to insert the field name like: username and assword. and then select the length (like 50, 30, 100 etc) as well as data type (recommend varchar) as your requirement and then click on save. OR You can watch the video for this designing part, you may understand better in video.

Some screenshot of creating database are:

How to Create Login Attempt Limit Form in PHP?
How to Create Login Attempt Limit Form in PHP?

How to Create Login Attempt Limit Form in PHP?
How to Create Login Attempt Limit Form in PHP?

How to Create Login Attempt Limit Form in PHP?
How to Create Login Attempt Limit Form in PHP?

NOTE: We have to insert username, password in our database. So, for this, Click on insert tab and insert username, password as:

How to Create Login Attempt Limit Form in PHP?
How to Create Login Attempt Limit Form in PHP?

3. After completing this task, write the following piece of code and save it in .php extension.


<!doctype html>
<?php
$servername="localhost";
$username="root";
$password="";
$dbname="loginattempt";
$atmp=0;
$conn = mysqli_connect($servername, $username, $password,$dbname);
if(isset($_POST['login'])){
$user=$_POST['user'];
$pass=$_POST['pass'];
$atmp=$_POST['hidden'];
if($atmp<4){
$query = "select * from loginattempt where username='".$user."' and password='".$pass."'";
$result = mysqli_query($conn, $query);
if($result){
if(mysqli_num_rows($result)){
while(mysqli_fetch_array($result, MYSQL_BOTH)){

echo'<script type="text/javascript">alert("you are login successfully")</script>';
?>
<script type="text/javascript">
window.location.href="newpage.php";
</script>
<?php
}
}
else{
$atmp++;

echo'<script type="text/javascript">alert("error and try again and the number of attemp is '.$atmp.'")</script>';
}
}
}
if($atmp==4){
echo'<script type="text/javascript">alert("login limit exceed")</script>';
}
}

?>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
</head>

<body>
<form method="post" action="">
<table align="center">
<?php
echo"<input type='hidden' name ='hidden' value='".$atmp."'>";

?>
<tr>
<td>Username</td>
<td><input type="text" name="user" <?php if($atmp==4){?> disabled="disabled" <?php } ?>placeholder="enter username"></td>
</tr>
<tr>
<td>Password</td>
<td><input type="password" name="pass" placeholder="enter password"></td>
</tr>
<tr>
<td></td>
<td><input type="submit" <?php if($atmp==4){?> disabled="disabled" <?php } ?> name="login" value="Login"></td>
</tr>
</table>
</form>
</body>
</html>

4. Open this .php file in any browser you want. 🙂 That’s it guyz.

if you have any confusion you can comment your confusion in the following comment section or watch the following videos:

 

Continue Reading
Blocking access to the login page after three unsuccessful login attempts using PHPHow to limit the number of login attempts in a login script?Limit Login Attemps using phpLimit Login Attempts with PHP & MySQLlimiting login attempts of user in phpLimiting Login Attempts phpLimiting user login attempts in PHPlogin attempt limit in phpphp count login attemptsprevent multiple login attempts phpSimple Login Page With Only 3 Password Attempts in PHPstate management in phpstate management in php using hidden fieldwrite php inside html elements
3 2,006
Share FacebookTwitterReddItWhatsAppPinterestEmail
Er. Ran Bahadur B.K.60 posts 56 comments

Ran Bahadur B.K. is the owner of TechSupportNep who is working with the aim of providing the quality Technology content. He is creating Tech and Programming videos, you can see all them in his YouTube Channel(https://www.youtube.com/TechSupportNep). He is also working with some company.

Prev Post

How to Generate and Send OTP SMS For Free using C#.NET?

Next Post

How to Generate and Send OTP SMS for Free Using java?

Show Comments (3)
Help Needed

This website is free of annoying ads. We want to keep it like this. You can help with your support:

Donate!

The need for Support! Why to Support?

If you need your own website? contact me!
erranbahadurbk
Fiverr
Seller
Hello there,This is me Ran Bahadur B.K., A graduated computer engineer. I have 3+ years of work experience in wordpress design and development. I have strong knowledge of HTML, CSS and PHP which are the three ingredients of web development. Currently i am working with the software company so i also have experience in desktop apps and mobile apps development.

Latest

Python

How to Create Login Application in Python using SQLite Database?

How to use View Binding in Android?

Windows 10 Build 1909 Features that you should know.

How to Create a Complete Login and Forgot Password System in java ?

Prev Next 1 of 15
  • About us
  • Contact us
  • Privacy Policy
  • Disclaimer
© 2022 All Rights Reserved.
Website By: Ran Bahadur B.K.