• 0

PHP script executing twice for no apparent reason


Question

I have a PHP script that runs twice for a certain (very important) user. I can not get it to run twice, even using the same browser. Unfortunately, I can't link to it here.

The script is part of a newsletter system I've been writing. In this particular section (actually creating and sending the letter) there are 3 pages - the first is where the administrator enters the subject, the newsletter and the category or categories of subscribers that it is to sent to. They then click on send and they got a confirmation page. This shows how many members are in the categories they selected and an overview of the letter. If they're happy, they then click on Confirm and the final script loops, going through the database and gets the details for each subscriber (name, email address, etc), personalizes it for that subscriber and sends off the email. The problem is that the final script will execute twice for a particular administrator, sending everyone two emails.

I've done some sniffing at log files and found that it is executed twice, rather than some bug making a large part of my script get looped twice. Interestingly, the first execution has the HTTP_REFERER set correctly to the confirmation page. The second call has no HTTP_REFERER set. The time difference between the 2 scripts being run is 0 seconds (all the logs are precise to just 1 second). I'm pretty sure the admin isn't calling it twice. I put in javascript to disable the submit button after it's clicked much like this board has for the reply button (in fact, very much like what this board has :shifty: ). Also, the HTTP_REFERER isn't set for the second execution when it should be. The fact that it is set for the first one shows that it is indeed working (I know thisn't 100% reliable). The newsletter details are passed on both executions (via POST).

I've helped the issue somewhat but it's treating symptoms, not the cause. The submit disabler failed completely but more successful is the anti-dup system I implemented. Each sent letter is saved for future viewing along with the time it was send - before running the main read member info/send email loop, I checked the saved messages for one with the same subject, body and any of the same subscriber categories that have been sent in the last 30 mins and quit with an error message if any are found. It works, but I'd like to fix it properly.

2 answers to this question

Recommended Posts

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Posts

    • Clear Linux is open source, indeed, so its source code is available for anyone. They're just shutting down its support from them, they're not forbidding anyone else from taking over.
    • Linux Mint is also my favorite distro, but I fear what will happen with it if Clem were to disappear tomorrow, to be honest.
    • Yeah, I totally get your point, which is possible it could happen. I just hope there is a few people around him who are similar to where if they took over things would run pretty much the same. if not, then yeah, it could start to decline rapidly etc. but I figure something that's been around for a longer period of time with a decent backing, and probably more users than most Linux distro's (which I would 'imagine' Mint is one of the more used Linux desktop distro's by volume of people who use it), is less likely to just disappear. but like you said, nothing is guaranteed. but I do think you are probably right in that Clem is probably the core of what keeps Mint, Mint. I like how it tends to stay pretty much the same with some slight tweaks here and there (but is largely the same) instead of that crap some people go for with change for the sake of change trying to create a overly fancy interface and other unnecessary stuff etc. I also feel Mint keeps a nice balance of things out-of-the-box where it's not too bloated, nor too striped down. p.s. but I see Mint as a better Ubuntu basically. but I get your point like if it was more of a really serious choice of needing a 'safe bet' to use long term, then yeah something like official Ubuntu would be one of the better choices for sure given what you said with it being backed by an actual company which makes it a safer bet than Mint which is smaller and 'could' potentially be more fragile.
    • It’s in development so hopefully it’s improved upon before release.
    • For the 10th iteration they could have bothered with some design changes rather than just carrying over the 9's
  • Recent Achievements

    • First Post
      leoniDAM earned a badge
      First Post
    • Reacting Well
      Ian_ earned a badge
      Reacting Well
    • One Month Later
      Ian_ earned a badge
      One Month Later
    • Dedicated
      MacDaddyAz earned a badge
      Dedicated
    • Explorer
      cekicen went up a rank
      Explorer
  • Popular Contributors

    1. 1
      +primortal
      506
    2. 2
      ATLien_0
      209
    3. 3
      Michael Scrip
      202
    4. 4
      Xenon
      146
    5. 5
      +FloatingFatMan
      121
  • Tell a friend

    Love Neowin? Tell a friend!