Debugging help - PHP include causes page refresh
I'm having a very odd problem that I can't seem to track down. Any help with regards to debugging would be greatly appreciated!
Let me describe this using scenarios.
Scenario 1 (incorrect)
- PHP calls out to a CAS server (using
curl_exec
) and gets the user info back - PHP开发者_如何学Go checks the database to ensure that the user returned from CAS exists and fails (which is correct, I'm testing a non-existent user) and sets the error message to "User not found" (this is the correct error message)
- PHP includes the
top.php
file - The page randomly refreshes or redirects to itself and starts the process over...this is what I can't figure out.
- PHP calls out to the CAS server (using
curl_exec
) and receives an error since the CAS ticket has already been used, setting a new error message of "CAS rejected your credentials" (which is not correct) - PHP includes the
top.php
file and doesn't refresh/redirect a second time - PHP prints out "CAS rejected your credentials" (which is not correct)
Scenario 2 (semi-correct)
- PHP calls out to a CAS server (using
curl_exec
) and gets the user info back - PHP checks the database to ensure that the user returned from CAS exists and fails (again, this is correct, I'm still testing a non-existent user) and sets the error message to "User not found" (this is the correct error message)
- I skip
top.php
since it was commented out, and print out "User not found" (this is the correct error message)
Debugging
So, I have checked, double-checked and triple-checked that top.php
doesn't use include
, require
, redirect
(a function we wrote that prints a <meta>
redirect tag and then calls exit;
), or any other thing that actually refreshes the page.
In fact, I've put in a die
statement that prints out the error message. On one line in top.php
, it prints out correctly. When I move that statement down one line (below an HTML </div>
tag), it refreshes the page and prints the incorrect error message. There aren't even any PHP tags anywhere close.
As far as I can tell, this means the problem is not actually in the top.php
file, since printing out </div>
should never cause a page to refresh/redirect.
Any ideas on how to debug from here would be enormously helpful. Clearing caches/buffers? How to better track what PHP is doing?
Note: No PHP errors are being output.
UPDATE: Yay, I found the culprit! Instead of calling include 'top.php';
I simply copied/pasted the code inside login.php
and it presented the same problem. So I began deleting lines until I found the one causing the problem:
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
So, switching the question entirely since I didn't have much of a question in the first place: Can someone explain why this causes a page refresh, and why is it only sometimes (i.e. it doesn't continually refresh the page)?
If you have firefox grab yourself a copy of livehttpheaders. Turn it on and go through scenario 1. Trace through the http request and response headers to see what is happening there. It should provide you with more information on just what is happening between the browser and the server.
精彩评论