The behavior was to drop back to the login screen.
Here is the code for the login process:
See if I missed something.
session_start();
include('config.php');
$user_table=(USER);
$admin_table=(ADMIN);
// username and password sent from form
$myusername=mysql_real_escape_string($_POST['username']);
$mypassword=mysql_real_escape_string($_POST['password']);
// first you would want to know if they attempted 10 times
if(isset($_SESSION['attempts']) && $_SESSION['attempts'] >= 10) {
header("Location:banned.html");
exit;
}
else {
$sql="SELECT attempts FROM $admin_table WHERE username='$myusername'";
$result=mysql_query($sql);
$count=mysql_num_rows($result);
//if found how many attempts do they have?
if ($count==1){
$row = mysql_fetch_array($result);
$attempts=$row['attempts'];
// if they have more than 9 send them to the banned page
if ($attempts>=10){
header("location:banned.html");
exit;
}
}
}
$q= "SELECT * FROM $admin_table WHERE username='$myusername' and password='$mypassword'";
$result= mysql_query($q)or die("Cannot find your login credentials " . mysql_error());
//$row = mysql_fetch_assoc($result);
//$dbpassword=$row['password'];
//echo 'entered password ';
//echo $mypassword;
//echo '<br />';
//echo 'database password';
//echo $dbpassword;
// If result matched $myusername and $mypassword, table row must be 1 row
if(mysql_num_rows($result) == 1) {
$row = mysql_fetch_assoc($result);
$_SESSION['username'] = $row['username'];
$_SESSION['useraccess'] = $row['access_level'];
$useraccess=$row['access_level'];
$q = "UPDATE $admin_table SET attempts = 0 WHERE username = '$myusername'";
$delattempts= mysql_query($q)or die(mysql_error());
// Log date and time
$sql = "UPDATE $admin_table SET last_login = '". date("Y-m-d h:i:s"). "' WHERE username = '$myusername'";
$logdate = mysql_query($sql) or die(mysql_error());
// Send to Admin index page
header("Location: http://example.com/testing/members/main/admin/index.php?$useraccess");
exit;
}
else {
$addattempt="UPDATE $admin_table SET attempts = attempts +1 WHERE username= '$myusername' ";
mysql_query($addattempt);
//send them back to the login page
header("location:index.php");
}
// If they are not found in the Admin table check the Member table
$sql="SELECT * FROM $user_table WHERE member_login='$myusername' and member_password='$mypassword'";
$result=mysql_query($sql);
// Mysql_num_row is counting table row
if(mysql_num_rows($result) == 1) {
$row = mysql_fetch_assoc($result);
// Register $myusername, $mypassword and redirect
$_SESSION['login']= $row['member_login'];
$_SESSION['id']= $row['contactid'];
$_SESSION['useraccess']= 'User';
header("location:http://example.com/testing/members/main/index.php");
exit;
}
else {
$_SESSION['attempts']=$_SESSION['attempts']+1;
header("location:index.php");
exit;
}
I have a no cache in the admin page:
//prevents caching
header("Expires: Fri, 01 Jan 1988 00:00:00 GMT");
header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
header("Cache-Control: post-check=0, pre-check=0",false);
session_cache_limiter();
Was thinking about passing the access in the url, but if it does that automatically, then...
I will add a no cache to the login process just to be safe.
[edited by: eelixduppy at 10:01 pm (utc) on Dec 9, 2011]
[edit reason] example.com [/edit]