[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Increment variable each time a form is posted

Posted on 2006-05-01
12
Medium Priority
?
250 Views
Last Modified: 2008-03-17
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
Comment
Question by:Luv2Muff
  • 4
  • 4
  • 4
12 Comments
 
LVL 17

Assisted Solution

by:BogoJoker
BogoJoker earned 1000 total points
ID: 16579878
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
 
LVL 11

Expert Comment

by:star_trek
ID: 16579903
It shows 1 because, the initial value from HTML(in input) is 0 and you incremented it by 1.
0
 

Author Comment

by:Luv2Muff
ID: 16580443

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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 11

Expert Comment

by:star_trek
ID: 16580462
Bogos comments should work, what is your HTML like?
0
 
LVL 17

Expert Comment

by:BogoJoker
ID: 16580472
Yes, could we see the entire page.  If you would like an example of this I can whip one up.
Joe P
0
 

Author Comment

by:Luv2Muff
ID: 16580553
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
 
LVL 11

Accepted Solution

by:
star_trek earned 1000 total points
ID: 16580601
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
 

Author Comment

by:Luv2Muff
ID: 16580824
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
 
LVL 17

Expert Comment

by:BogoJoker
ID: 16580844
Give star_trek a few more points =)
He is so close to his Master Certification!

Joe P
0
 
LVL 11

Expert Comment

by:star_trek
ID: 16580861
Never Mind Joe we can split evenly.
0
 

Author Comment

by:Luv2Muff
ID: 16581533

And nice guys too !!
0
 
LVL 17

Expert Comment

by:BogoJoker
ID: 16582740
Hehe =)
0

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this. Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it i…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses
Course of the Month18 days, 14 hours left to enroll

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question