Block access after 3 bad attempts |
6/26/2006 2:04:15 PM |
PHPRunner General questions | |
O
osluk author
I followed the instructions in the article http://xlinesoft.com/articles/system_access_lock.htm |
|
![]() |
Admin 6/27/2006 |
Chris, |
O
|
osluk author 6/27/2006 |
<?php function BeforeLogin($username, $password) { //** Custom code **** // check if this IP address is currently blocked global $conn; $sql = "select Attempts, LastLogin from LoginAttempts where ip = '" . $_SERVER["REMOTE_ADDR"] . "'"; $rs = db_query($sql,$conn); $data = db_fetch_array($rs); if (!$data || !strlen($data["LastLogin"])) return true; $atime = db2time($data["LastLogin"]); $time = mktime($atime[3],$atime[4],$atime[5],$atime[1],$atime[2],$atime[0]); $diff = (time()-$time)/60; if ($data["Attempts"]>=3) { if($diff<30) { echo "<p align=center> <font color=red><b>Access denied for 30 minutes</b> <font></p>"; return false; } else { db_exec("update LoginAttempts set Attempts=0 where ip = '" . $_SERVER["REMOTE_ADDR"] . "'",$conn); return true; } } return true; } function AfterSuccessfulLogin() { //** Custom code **** // clear previous attempts global $conn; db_exec("update LoginAttempts set Attempts=0 where ip = '" . $_SERVER["REMOTE_ADDR"] . "'",$conn); } function AfterUnsuccessfulLogin() //** Custom code **** // increase number of attempts // set last login attempt timeif required { global $conn; $sql = "select * from LoginAttempts where ip = '" . $_SERVER["REMOTE_ADDR"] . "'"; $rs = db_query($sql,$conn); $data = db_fetch_array($rs); if($data) { $attempts = $data["Attempts"]+1; if($attempts==3) db_exec("update LoginAttempts set Attempts=" . $attempts . ", LastLogin=now() where ip = '" .$_SERVER["REMOTE_ADDR"] . "'",$conn); else db_exec("update LoginAttempts set Attempts=" . $attempts . " where ip = '" .$_SERVER["REMOTE_ADDR"] . "'",$conn); } else db_exec("insert into LoginAttempts (Attempts,IP,LastLogin) values (1, '".$_SERVER["REMOTE_ADDR"] . "',NOW())",$conn); } function BeforeRegister($userdata) { // Parameters: // $userdata - Array. // Each field on this form represented as 'Field name'-'Field value' pair //** Insert a record into another table **** global $conn; $IP = $_SERVER["REMOTE_ADDR"]; $User = @$_SESSION["UserID"]; $AccessType = "Registration Before"; $strSQLInsert = "insert into audit (IP,User,AccessType,DateTime) values ('$IP','$User','$AccessType',NOW())"; db_exec($strSQLInsert,$conn); return true; // return true if you like to proceed with registration // return false in other case } function AfterSuccessfulRegistration() { //** Insert a record into another table **** global $conn; $IP = $_SERVER["REMOTE_ADDR"]; $User = @$_SESSION["UserID"]; $AccessType = "Registration OK"; $strSQLInsert = "insert into audit (IP,User,AccessType,DateTime) values ('$IP','$User','$AccessType',NOW())"; db_exec($strSQLInsert,$conn); } function AfterUnsuccessfulRegistration() { //** Insert a record into another table **** global $conn; $IP = $_SERVER["REMOTE_ADDR"]; $User = @$_SESSION["UserID"]; $AccessType = "Registration Fails"; $strSQLInsert = "insert into audit (IP,User,AccessType,DateTime) values ('$IP','$User','$AccessType',NOW())"; db_exec($strSQLInsert,$conn); } ?>
|
![]() |
Admin 6/27/2006 |
Chris, |
O
|
osluk author 6/28/2006 |
What I meant I gues was is there a specific order they have to be in. |
![]() |
Admin 6/28/2006 |
Chris, function AfterSuccessfulLogin() { //** Display a message on the Web page **** echo "Your message here"; //** Redirect to another page **** header("Location: anypage.php"); exit(); } |
O
|
osluk author 6/28/2006 |
Thanks Fatal error: Cannot redeclare aftersuccessfullogin() (previously declared in /hsphere/local/home/bauduc-dev/bordeauxreport.com/db-2005/AdminD/include/events.php'>bordeauxreport.com/db-2005/AdminD/include/events.php:41'>bordeauxreport.com/db-2005/AdminD/include/events.php'>bordeauxreport.com/db-2005/AdminD/include/events.php:41) in /hsphere/local/home/bauduc-dev/bordeauxreport.com/db-2005/AdminD/include/events.php'>bordeauxreport.com/db-2005/AdminD/include/events.php on line 71 function AfterSuccessfulLogin() { //** Custom code **** // clear previous attempts global $conn; db_exec("update LoginAttempts set Attempts=0 where ip = '" . $_SERVER["REMOTE_ADDR"] . "'",$conn); } { //** Insert a record into another table **** global $conn; $IP = $_SERVER["REMOTE_ADDR"]; $User = @$_SESSION["UserID"]; $AccessType = "Login OK"; $strSQLInsert = "insert into audit (IP,User,AccessType,DateTime) values ('$IP','$User','$AccessType',NOW())"; db_exec($strSQLInsert,$conn); }
Fatal error: Call to undefined function: db_exec() in /hsphere/local/home/bauduc-dev/bordeauxreport.com/db-2005/AdminD/include/events.php'>bordeauxreport.com/db-2005/AdminD/include/events.php on line 53
|
O
|
osluk author 6/29/2006 |
After a lot of trial and error I have this working.
|
![]() |
Admin 6/29/2006 |
Chris, |