PHP seems to execute script twice PHP seems to execute script twice apache apache

PHP seems to execute script twice


echo '<pre>'; //Headers and cookies already sent.session_start(); //Cannot set cookie anymore, system tries again, I guess

Start session first, then output anything.Try placing session_start(); on top


I can't thank the poster of this question enough. His session test made me realize that I had the same problem of a php script running several times.

In my script I had two PDO functions seperated from each other by an if-else-construct. One was a simple select, and one a simple insert function. But everytime I ran the script, both pdo commands got executed. PDO ended up writing rows in my table which had the entry 'public'.

So what happened? My page got send multiple times because of ELEMENTS IN THE HTML CODE THAT COULD NOT BE FOUND. In my case that was a css file which was named incorrectly. When I solved that (after 4 hours of looking at code) the problem disappeared. Also broken images for example trigger the same event.


Oke folks, found a completely insane solution to this problem. Just posting for future reference. I recently installed a HTML validator in Chrome (an extension). This seems to be the culprit. After everything has loaded, the validator seems to be re-requesting the page so it is executed twice. Nice plugin. Not!Took me about half a day to figure this out.