doude4201 2011-02-17 22:53
浏览 27
已采纳

调试帮助 - PHP包括导致页面刷新

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)

  1. PHP calls out to a CAS server (using curl_exec) and gets the user info back
  2. PHP 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)
  3. PHP includes the top.php file
  4. The page randomly refreshes or redirects to itself and starts the process over...this is what I can't figure out.
  5. 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)
  6. PHP includes the top.php file and doesn't refresh/redirect a second time
  7. PHP prints out "CAS rejected your credentials" (which is not correct)

Scenario 2 (semi-correct)

  1. PHP calls out to a CAS server (using curl_exec) and gets the user info back
  2. 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)
  3. 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)?

  • 写回答

1条回答 默认 最新

  • dongtiao0279 2011-02-17 23:03
    关注

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了