• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 254
  • Last Modified:

Increment variable each time a form is posted

Any ideas why this does not work? At the moment it always shows a value of 1

                 <input type="hidden" name="loginAttemptCheck" value="0"/>

       <?php if (array_key_exists('loginAttemptCheck', $_POST)) {
       $_POST['loginAttemptCheck']++;
                 echo 'loginAttempts: ' . $_POST['loginAttemptCheck'];}

Thanks in advance.

Luv2.
0
Luv2Muff
Asked:
Luv2Muff
  • 4
  • 4
  • 4
2 Solutions
 
BogoJokerCommented:
Hi Luv2Muff,

It looks like you are always setting the value to 0, then incrementing to 1 with the php code.
Maybe you should dynamically set the value.  Lets say a failed login POSTs to the current login page, then:
<input type="hidden" name="loginAttemptCheck" value="<?php echo $_POST['loginAttemptCheck']; ?>"/>

Now the value will keep incrementing because its state is saved and used, rather then being 0 every time.


Joe P
0
 
star_trekCommented:
It shows 1 because, the initial value from HTML(in input) is 0 and you incremented it by 1.
0
 
Luv2MuffAuthor Commented:

Thanks Joe,

I have tried as you said (see below) however loginAttemptCheck still stays at 1.

Any further ideas?

Thanks,

Luv2.

<input type="hidden" name="loginAttemptCheck" value="<?php echo $_POST['loginAttemptCheck']; ?>"/>

<?php if (array_key_exists('loginAttemptCheck', $_POST)) {
$_POST['loginAttemptCheck']++;
echo 'loginAttempts: ' . $_POST['loginAttemptCheck'];}
0
Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

 
star_trekCommented:
Bogos comments should work, what is your HTML like?
0
 
BogoJokerCommented:
Yes, could we see the entire page.  If you would like an example of this I can whip one up.
Joe P
0
 
Luv2MuffAuthor Commented:
Hi,

Many thanks for your continued hepl on this, here is the whole include:

<div id="client_login">
  <div class="form">
      <h1>Client Login</h1>
      <p>Use this area to securely view, give feedback and approve proofs.</p>
      <form name="login" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
         <p>
            <label for="login_name">Username:</label>
            <input name="login_name" type="text" id="login_name" value="" />
          <input type="hidden" name="loginAttemptCheck" value="<?php echo $_POST['loginAttemptCheck']; ?>"/>
         </p>
         <p>
            <label for="login_pass">Password:</label>
            <input name="login_pass" type="text" id="login_pass" value="" />
         </p>
         <p><label for="remember" style="width:130px">Remember my login details:</label><input name="remember" type="checkbox" style="width:15px" value="" /></p>
         <p><a href="#">I have forgotten my login details</a></p>
         <p>
            <input type="submit" name="login_Submit" value="Submit" class="submit" />
         </p>
       <?php if (array_key_exists('loginAttemptCheck', $_POST)) {
       $_POST['loginAttemptCheck']++;
         echo 'loginAttempts: ' . $_POST['loginAttemptCheck'];}
      
       if ( $logincount >= 2 ) {
         echo '<div style="clear: right; height:1px"><!-- --></div><div class="serverValMsg"><h1>WARNING</h1>
       <p style="color:#55B4EA"><b>Unauthorised login attempt</b><br>Your IP address = ' . $_SERVER['REMOTE_ADDR'] . '<br><i>This attempt has been recorded and the system administrators have been notified</i></p></div>';
         } else {
         echo '<div style="clear: right; height:1px"><!-- --></div>1st attempt';
         } ?>
      </form>
      <div style="clear: right; height:1px"><!-- --></div>
   </div><!-- Close form -->
</div><!-- Close login -->
0
 
star_trekCommented:
put the PHP code
<?php if (array_key_exists('loginAttemptCheck', $_POST)) {
      $_POST['loginAttemptCheck']++;
         echo 'loginAttempts: ' . $_POST['loginAttemptCheck'];}
before the
 <input type="hidden" name="loginAttemptCheck" value="<?php echo $_POST['loginAttemptCheck']; ?>"/>
0
 
Luv2MuffAuthor Commented:
Hey that works - MANY THANKS !!!!

Would you mind if I split the points evenly?

Thanks again (I may get some sleep tonight after all)

Luv2.
0
 
BogoJokerCommented:
Give star_trek a few more points =)
He is so close to his Master Certification!

Joe P
0
 
star_trekCommented:
Never Mind Joe we can split evenly.
0
 
Luv2MuffAuthor Commented:

And nice guys too !!
0
 
BogoJokerCommented:
Hehe =)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

  • 4
  • 4
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now