Created
September 19, 2017 13:17
-
-
Save LinuxPhreak/e0fff5a4e4dc036da383ba59cd6e779e to your computer and use it in GitHub Desktop.
Working Example Of A 3 Login Limit For A Website
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| if (isset($_POST['submit'])) | |
| { | |
| $datetime = date('Y-m-d H:i:s'); | |
| $username = htmlentities(trim(mysqli_real_escape_string($dbc,$_POST['username']))); | |
| $check_user = mysqli_query($dbc,"SELECT * FROM attempts WHERE user='$username'"); | |
| $ip = $_SERVER['REMOTE_ADDR']; | |
| if (mysqli_num_rows($check_user) > 0) | |
| { | |
| $date_check = mysqli_query($dbc,"SELECT * FROM attempts WHERE user='$username' AND datetime > (NOW() - INTERVAL 30 MINUTE)"); | |
| $date = mysqli_fetch_assoc($date_check); | |
| if ($_POST['username'] == $date['user'] && $date['attempt'] == 0) | |
| { | |
| mysqli_query($dbc,"UPDATE attempts SET attempt=1 WHERE datetime > (NOW() - INTERVAL 30 MINUTE)"); | |
| } | |
| else if ($_POST['username'] == $date['user'] && $date['attempt'] == 1) | |
| { | |
| mysqli_query($dbc,"UPDATE attempts SET attempt=2 WHERE datetime > (NOW() - INTERVAL 30 MINUTE)"); | |
| } | |
| else if ($_POST['username'] == $date['user'] && $date['attempt'] == 2) | |
| { | |
| mysqli_query($dbc,"UPDATE attempts SET attempt=3 WHERE datetime > (NOW() - INTERVAL 30 MINUTE)"); | |
| } | |
| else if ($_POST['username'] == $date['user'] && $date['attempt'] == 3) | |
| { | |
| echo 'To many attempts'; | |
| } | |
| } | |
| else | |
| { | |
| mysqli_query($dbc,"INSERT INTO `attempts` (`user`,`ip`,`attempt`,`datetime`) VALUES ('$username','$ip',0,'$datetime')"); | |
| echo 'Field Added'; | |
| } | |
| } | |
| ?> | |
| <form method="post"> | |
| Username: <input type="text" name="username" placeholder="username" /> | |
| <input type="submit" name="submit" value="Submit" /> | |
| </form> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment