Thank you for posting the PHP code.
First think you should take a look at is the random generator RF01. You can see the counter for every item on the right side.
If these number exceed the number of completed/usable questionnaires, then you may have an issue with drop-outs. If the drop-out is already on the first page, you may consider putting the welcome page (where most people close the browser tab, compared to later occasions) in the main questionnaire, and the PHP code on page two.
Generally, this solution will not (!) check if respondents do the questionnaire or close the browser window immediately (or anything in between). Therefore, if you have a severe mis-distribution, then this might be an effect of your stimulus. Creating a cross-table between QUESTNNR, FINISHED and LASTPAGE is usually a good start.