PHP Javascript page loads twice
I have written this small site, with registration and everything, and I got to a point I think I am not too sure what is happening. It first started as the DB reporting to me that the user I am trying to write into the DB has a duplicate entry (where it should be unique), which really puzzled me, how can it be that I have duplicate ? Well. It took me three days to realize that the page is being somehow called twice !
I put a
$_SESSION['one']=0;
and a
$_SESSION['two']=0;
in the topmost and bottommost parts of the page accordingly.
then I changed them both to ++
, so I can check how many times they have been passed through.
I used the verification link from the emaill the site has sent, and tested their values.
Strangely enough, 'one' would equal 2 and 'two' would equal 1
...
This explains exactly why all worked registration-wise, but I got all those errors about those duplicates. Though, I used firebug to trace any redirections, but couldn't see anything... It shows the page has 12 GETs and a POST. 开发者_开发百科 I was hoping to bump into a redirect and debug accordingly, but alas, or maybe I don't know how to use firebug to trace these redirects...
I would appreciate any suggestion Thanks in advance!
Like I said in the comments, here is the answer that worked for me and Ted:
What I do to fix it is change my doctype to html 5 and then validate the page using w3c validator, this problem was only occurring for my in firefox using firebug.
Do you have some <img>
or <script>
with src=""
? Or maybe some <link>
stylesheet with empty href
?
Is firebug showing you, in net tab, that your site is called twice?
This kind of issues usually happen when you have a fatal or otherwise unignorable error that forces PHP to terminate you script early, in the midst of processing a request.
Check you error log for details of happening.
It is Firebug that is causing the page to load twice. Apparently changing the doctype to html5 as:
instead of html4 has overridden that bug. When you are going to deploy your site, go back to html 4, and of course, always keep the server safe from such bugs. Use DB constraints, validation and escaping when needed. Hope this helps, and Big thanks to @jeffreydev!!
精彩评论