dongwei2882 2013-05-10 13:48
浏览 49

网页上的PHP XML或Json选择

I am using the get parameters so the user can choose XML output or Json. Upon their choice it either runs a json function or a xml function, on the same page. However, despite my efforts, even though the code is never told to enter the XML function while json is selected, it still runs the header("Content-type: text/xml"); within the XML function. It does not run anything else. The problem is when it attempts to write:

header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); 
header("Last-Modified: " . gmdate( "D, d M Y H:i:s" ) . "GMT"); 
header("Cache-Control: no-cache, must-revalidate"); 
header("Pragma: no-cache");
header("Content-type: application/json");

In the json function, it gives me an error that the header has already been altered (even though I never executed the XML function. I had to remedy that by making a separate webpage, one for json and one for xml. However, I would like them to goto the same URL and grab the gets to select if they want json or XML without any errors. Is there an easier way to do this?

  • 写回答

1条回答 默认 最新

  • dtf24224 2013-05-10 16:17
    关注

    check the documentation on header. you may have to set

    header("Content-type: application/json", true);
                                             ####
    

    to make sure your new content-type header replaces the Content-type header that may have already been set. http://php.net/header

    评论

报告相同问题?

悬赏问题

  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)