• 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.