PDA

Click to See Complete Forum and Search --> : [RESOLVED] php mysql login script with ip ban


richsmith
Jul 23rd, 2005, 09:43 AM
hi there,
i have just made a log in script which works well, however i would like to be able to make it so that if someone attempts to login but fails 3 times then their ip is banned for a certain amount of time:
i have a table with bannedip, time(type datetime) and id,
i dont really know how to do this.
here is my code:

if( (!$username) or (!$password) )
{ header("Location:$HTTP_REFERER"); exit(); }

require ("conn.php");

$sql="select * from aplace where username=\"$username\" and password = password(\"$password\")";

$rs=mysql_query($sql,$conn)
or die("Error in query");

$num = mysql_numrows($rs);

if($num != 0)
{ $msg = "Welcome $username - you have logged in";
setcookie("user","in");}
else
{ header("Location:$HTTP_REFERER"); exit(); }

BIOSTALL
Jul 23rd, 2005, 07:07 PM
The way i would do it is to use a session variable that would increase by one each time the user fails to log in. When this session variable reaches 3, Add their IP address to your table.

Just ask if you need further explanation..

Hope that helps,

BIOSTALL

richsmith
Jul 25th, 2005, 12:55 PM
thanks,
i have completed it and it works