Donation bug

    This site uses cookies. By continuing to browse this site, you are agreeing to our Cookie Policy.

    The forums have been archived. Please read this thread for more information.

    • Donation bug

      Well, as you can see if you check the donation logs, it's possible to alter the form and donate any amount you want. Donating less than 1 euro results in it displaying 0, however. I decided to check this because it's a fairly common bug in paypal donation systems, but it's easy to fix.

      All you really need is to modify the PHP a little bit. As you can see from the donation page, we have multiple amounts to choose from on the list. For now, because it's easier, let's take a few of them. "5, 7, 10, 15, 20, 30"

      In the PHP code for where we handle the form submit (assuming it doesn't go straight to paypal, because it shouldn't! There should be a middle-man!), we should get the amount. It should be in, say, $_POST['amount']. All we need for this simple check an array. The array will contain the values from our list of possible donation amounts (as per before, we're only using up to 30 for now, for the sake of ease.) So we create an array with the amounts.

      PHP Source Code

      1. $valid_amounts = array(5, 7, 10, 15, 20, 30);


      And since we're not allowing decimal donations, we can use the easier way to make the amount submitted "safe"

      PHP Source Code

      1. $donation_amount = intval($_POST['amount']);


      Now, all we need to do is check whether or not it's in the array of valid amounts or not!

      PHP Source Code

      1. if (!in_array($donation_amount, $valid_amounts))


      So the final test code would look like this:

      PHP Source Code

      1. <?php
      2. $valid_amounts = array(5, 7, 10, 15, 20, 30);
      3. $donation_amount = intval('0.1');
      4. if (!in_array($donation_amount, $valid_amounts)) {
      5. // Do something about this!
      6. echo('Sorry, you\'ve attempted to donate an invalid amount! This has been logged!');
      7. //someLogFunction('invalid donation amount', $_SERVER['REMOTE_ADDR']);
      8. } else {
      9. echo('Thank you for your donation!');
      10. }
      11. ?>
      Display All

      Check me out (or not): YouTube , deviantART , Useless Webpage .