thomasw_lrd Posted September 6, 2012 Share Posted September 6, 2012 I'm trying to create a vcard from our database, but I keep running into headers already sent error. Warning: Cannot modify header information - headers already sent by (output started at in on line 102 Warning: Cannot modify header information - headers already sent by (output started at ) in on line 103 I understand why the error is occurring, but is there any way around it? I want to create a downloadable vcard on the fly. Any help would be appreciated. Quote Link to comment https://forums.phpfreaks.com/topic/268084-php-headers-some-way-to-redirect-them/ Share on other sites More sharing options...
requinix Posted September 6, 2012 Share Posted September 6, 2012 The way "around" it is to fix it. Move your header() to someplace before line 102, or vice-versa. Quote Link to comment https://forums.phpfreaks.com/topic/268084-php-headers-some-way-to-redirect-them/#findComment-1375839 Share on other sites More sharing options...
thomasw_lrd Posted September 6, 2012 Author Share Posted September 6, 2012 The way "around" it is to fix it. Move your header() to someplace before line 102, or vice-versa. I can't. This is a "legacy" system. I'm trying to call a function to create the vcard with, but it won't let me output it, since my headers are already sent. Quote Link to comment https://forums.phpfreaks.com/topic/268084-php-headers-some-way-to-redirect-them/#findComment-1375840 Share on other sites More sharing options...
PFMaBiSmAd Posted September 6, 2012 Share Posted September 6, 2012 You can only output one content-type per http request. For the http request for your web page, you cannot switch in the middle and try to download a vcard. You must put a link to the vcard that you want to be downloaded. If that vcard is dynamically created, the link would be to the .php script that creates the vcard. The .php script would retrieve the data from your database, output the correct content-type header, followed by the dynamically produced vcard data. The one thing that you could do to your current code that would allow the vcard download to work, would prevent the web page up to that point from being output, so it would be kind of pointless. Quote Link to comment https://forums.phpfreaks.com/topic/268084-php-headers-some-way-to-redirect-them/#findComment-1375842 Share on other sites More sharing options...
thomasw_lrd Posted September 6, 2012 Author Share Posted September 6, 2012 You can only output one content-type per http request. For the http request for your web page, you cannot switch in the middle and try to download a vcard. You must put a link to the vcard that you want to be downloaded. If that vcard is dynamically created, the link would be to the .php script that creates the vcard. The .php script would retrieve the data from your database, output the correct content-type header, followed by the dynamically produced vcard data. The one thing that you could do to your current code that would allow the vcard download to work, would prevent the web page up to that point from being output, so it would be kind of pointless. That's exactly the solution I just thought of. Thank you very much. Quote Link to comment https://forums.phpfreaks.com/topic/268084-php-headers-some-way-to-redirect-them/#findComment-1375843 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.