Member Avatar

Please correct the two syntax errors after " exit; " on line 8 and 16.

code below:

$bad_login_limit = 3;
$lockout_time = 600;
$first_failed_login = failed_login_count; // retrieve from DB

if(     ($failed_login_count >= $bad_login_limit)  && (time() - ($first_failed_login) < $lockout_time) ) 
    { echo "You are currently locked out." ; } exit; // or return, or whatever.
 else if( /* login is invalid */ ) {
  if( time() - $first_failed_login > $lockout_time ) {
    // first unsuccessful login since $lockout_time on the last one expired
    $first_failed_login = time(); // commit to DB
    $failed_login_count = 1; // commit to db
  } else {
    $failed_login_count++; // commit to db.
  exit; // or return, or whatever.
} else {
  // user is not currently locked out, and the login is valid.
  // do stuff

Recommended Answers

All 6 Replies

Member Avatar

If you indented and structured your conditional blocks properly, you could correct it yourself. If you do that, the issue should be obvious.

Dang I almost gave him the answer before I read your response diafol. Well said Sir!

The best solution is already written, once you see it too, then this or anything like it will generate the headslap moment for you that is does for others,
to help you complete the self-help described, get a code-completing editor
Many basic editors, notepad replacements, programmer's editors, and whatever else the editor may be called, have code completion built in.

When you leave out some neccessary element, a closure, a semi-colon, a quote, or place elements in position that creates a headslap,
the code changes color at that point determined by the editor to require a code change,
to demonstrate there is something amiss

I use notepad++portable and notepad2-portable, you may choose any that appeal, but any will help solve this problem

headslap: noun: extreme facepalm

you cannot exit when you are already outside the block.

<Grin> to the OP
it has been
about proper indenting and structure to make it easier,
about closure positions,
about exit being outside the code block

now if you can't see that because of the poor code formatting,
there are exits outside the code block where they should be, and you have to move the block closure so the exit is inside the closure, then, . . .
doh headslap moment
dunno what else to write

another hint, the errors are before }exit;, and should be after exit;}

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.