Jump to content

Recommended Posts

i would probably do this with a db yes, set an if else condition checking if the user was successful in logging in or not...if they aren't successful...use an update query to update a field called something like "tries" and increment it by 1 each failed attempt

Link to comment
https://forums.phpfreaks.com/topic/244148-3-tries-for-login/#findComment-1253848
Share on other sites

does this work?:

 

<?php
if (isset($_POST['login']) && (isset($login_errors))) {
$IP = $_SERVER['SERVER_ADDR'];
$query = "SELECT * FROM login_attempts WHERE IP='$IP'";
$result = mysql_query($query) or die(mysql_error());
if (mysql_num_rows($result) > 0) { // If this user is already in the DB, we give them the appropiate message
	$row = mysql_fetch_array($result) or die(mysql_error());
	if ($row['tries'] == 3) {
		if (!(time() > $row['later_time'])) {
			$later_time = time() + 600; // This is 10 minutes
			echo "You've had your 3 failed attempts at logging in and now are locked out for 10 minutes. Please try again later!";
			if (empty($row['time']) || empty($row['later_time'])) {
				mysql_query("UPDATE login_attempts SET time = '$time'");
				mysql_query("UPDATE login_attempts SET later_time = '$later_time'");
			}
		} else {
			echo "you may login now!";
		}
	} else {
		$tries = $row['tries']+1;
		mysql_query("UPDATE login_attempts SET tries = '$tries'");
		$tries = 3 - $row['tries'];
		echo "You have $tries tries left.";
	}
} else {
	mysql_query("INSERT INTO login_attempts (tries, IP) VALUES ('1', '$IP')");
	echo "This is your first attempt to login. After your third attempt, you will be locked out of your account for 10 minutes.";
}
} 
?>

Link to comment
https://forums.phpfreaks.com/topic/244148-3-tries-for-login/#findComment-1253903
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.