PDA

View Full Version : lock record


nanny
12-19-2006, 10:30 PM
Hi davidj
Just wanting to know how I can:
////////// insert your sql update script here locking the account (just add a L for lock to the status field in your user table

In my database table I already have a status field showing active, inactive using radio buttons because I want to approve listings before they are entered.
Do I still do it this way?
I already have the system on inactive by default, does this make a difference?
Sorry not knowing what the L will do I am using php4 and mysql 4.1
Thanks

davidj
12-19-2006, 10:40 PM
the L does nothing and is just a flag

i can then query the flag before i do any updating or deleting

user 1 selects a datarow for editing,,, the row is tested for a Lock flag if no flag is found allow edit and lock the row ,,, user2 tries to edit the same row but the lock check discovers an L and then reports back the row status

nanny
12-19-2006, 11:08 PM
thanks
I am a little lost.
I was looking at your fantastic help with lock the log in script after 3 attempts.
Just wondering then how to add it to the dreamweaver code I already have working well.
I know you have your login script here.
my example is:

<?php
session_start();

$loginFormAction = $_SERVER['PHP_SELF'];
if (isset($accesscheck)) {
$_SESSION['PrevUrl'] = $accesscheck;
}

if (isset($_POST['username'])) {
$loginUsername=$_POST['username'];
$password=$_POST['password'];
$MM_fldUserAuthorization = "";
$MM_redirectLoginSuccess = "thanks.php";
$MM_redirectLoginFailed = "signin.php?badlogin=true";
$MM_redirecttoReferrer = false;
mysql_select_db($database_config, $config);

$LoginRS__query=sprintf("SELECT reg_username, reg_password FROM regid WHERE reg_username='%s' AND reg_password='%s'",
get_magic_quotes_gpc() ? $loginUsername : addslashes($loginUsername), get_magic_quotes_gpc() ? $password : addslashes($password));

$LoginRS = mysql_query($LoginRS__query, $config) or die(mysql_error());
$loginFoundUser = mysql_num_rows($LoginRS);
if ($loginFoundUser) {
$loginStrGroup = "";

//declare two session variables and assign them
$_SESSION['MM_Username'] = $loginUsername;
$_SESSION['MM_UserGroup'] = $loginStrGroup;


if (isset($_SESSION['PrevUrl']) && false) {
$MM_redirectLoginSuccess = $_SESSION['PrevUrl'];
}
header("Location: " . $MM_redirectLoginSuccess );
}
else {
header("Location: ". $MM_redirectLoginFailed );
}
}
?>
I haven't given the access levels here yet as I am still learning.
Should I have a recordset to check for the userid first?
Sorry for all the questions, I am keen to learn how to modify the dreamweaver code as I like using the recordsets for testing.
Thanks.

davidj
12-20-2006, 07:56 AM
what are you after here?

You want the login to be locked so no others can logon using those account details ??

nanny
12-21-2006, 09:59 PM
Hi davidj
Yes I want to have multi access rights upon whether they have paid or not.
Also
I want to be able to apply the 3 attempts feature.
QUOTE:

if ($row['user_id']){ // found user through ID


$_SESSION['counter'] = $_SESSION['counter'] + 1; // start counting attempts

if ($_SESSION['counter'] > 3){

(in here is it a new log in script or the first one?)////////// insert your sql update script here locking the account (just add a L for lock to the status field in your user table

header("location:includes/logout.php?r=4"); // send user to the logout script page which kills all sessions
exit;
}

}


I have also read on Google about: sleep(rand(5, 10)); for after xx tries with session cookie validation.
I am still trying to work out the 5,10 does it mean it will allow 5 attempts then sleep for 10 minutes for that session cookie.
Would I be able to apply your counter script with this?

Soooo many questions..............
Thanks, I am new to code and when I see it I try to understand it so that I can re-use it later instead of asking all the time.
Thanks for your time.

davidj
12-21-2006, 11:12 PM
dont know where you got that info from on sleep(rand(5, 10));

all sleep does is suspend a script from running for n seconds so if you added a sleep(10) then your page wont return for 10 seconds after the sleep has executed

the rand(5, 10) just selects a random number between 5 and 10