Modify Headers With Php - Not Working?

liunx

Guest
I just signed up with TCH, and in transferring my pages over from my old host, one of my PHP scripts seems to have broken.<br /><br />I need to ensure that my students see a fresh page of homework listings when they access the homework page each day (long story short, most students connect through the university servers, which cache old copies for an excessively long time). So I include this in each homework.php page:<br /><br /><!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1--><?php header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");<br />header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");<br />header("Cache-Control: no-store, no-cache, must-revalidate");<br />header("Pragma: no-cache"); ?><!--c2--></div><!--ec2--><br /><br />Which effectively flushes and prevents all caching of those pages. This has worked perfectly before, on my old host (evil Featureprice), and if possible I'd like to keep it working at TCH. But now, when I access that page, I get the php warning:<br /><br /><!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->Warning: Cannot modify header information - headers already sent by (output started at /home/nthulee/public_html/102/hausaufgaben.php:8) in /home/nthulee/public_html/102/hausaufgaben.php on line 10<br /><br />Warning: Cannot modify header information - headers already sent by (output started at /home/nthulee/public_html/102/hausaufgaben.php:8) in /home/nthulee/public_html/102/hausaufgaben.php on line 11<br /><br />Warning: Cannot modify header information - headers already sent by (output started at /home/nthulee/public_html/102/hausaufgaben.php:8) in /home/nthulee/public_html/102/hausaufgaben.php on line 12<br /><br />Warning: Cannot modify header information - headers already sent by (output started at /home/nthulee/public_html/102/hausaufgaben.php:8) in /home/nthulee/public_html/102/hausaufgaben.php on line 13<!--c2--></div><!--ec2--><br /><br />Can I not modify header info at TCH? If not, yikes. If that's not it, is it possible that it's merely because my name servers haven't propagated yet? I'm accessing the pages via the temporary IP-based URL -- once propagation occurs, might this work? Or am I out of luck? Any other ways to prevent cached files?<!--content-->
lynkali,<br /><br />I did some tests on some of my php pages and my script worked without the error. I am reading the Beginning PHP 4 book by wrox and they have a script like that in there as well.<br /><br />Page 52 if you have the book.<br /><br />Here is the code I used and is from the book:<br /><br /><!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1--><?php<br />header("cache-control: no-cache, must-revaildate");<br />header("pragma: no-cache");<br />header("expires: mon, 26 jul 1997 05:00:00 GMT");<br />?><!--c2--></div><!--ec2--><br /><br />I also tried to put the code below a PHP script that was already on the page and it gave me the same error you are receiving. So you should probably put the cache code as the very first php tag on the page. I do not use include files yet so you may want to test its position with the include statements if you use them.<br /><br />Scott<!--content-->
Thanks for testing it. It still doesn't work on mine (it's the very first php element, so it should be getting called right away before anything else). I don't use includes, so it's not that, either. About the only thing left is the nameservers, which haven't propagated yet. At this point I'll wait until they propagate so I can access the proper domain name -- if it still doesn't work then, well, then I'll have to figure something out. At least it works for you, so I know I'll eventually get it solved. <img src="http://www.totalchoicehosting.com/forums/style_emoticons/default/smile.gif" style="vertical-align:middle" emoid=":)" border="0" alt="smile.gif" /> <br /><br />Thanks!<!--content-->
I meant to respond to that too. <br /><br />When my domain was still propagating I was having all sorts of issues as well. in fact some of my php pages wouldn't even show up at all. so I just waited and it started to work fine the next day<!--content-->
That error is appearing because you have something that is outputting something to the browser before sending out the HTTP headers - HTTP headers must be sent before everything else. I don't think it's a domain related problem.<br /><br />PHP says the problem is on line 8 of your script:<br /><!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->output started at /home/nthulee/public_html/102/hausaufgaben.php:8<!--c2--></div><!--ec2--><br /><br />Check out that line on that file, you'll probably find something there that's outputting some stuff you don't want.<br /><br />By the way, I like your spirit of putting up a webpage for your students. I whish there were professors like you here in Portugal... at least on my university... most of them do have a webpage for their classes but they're all very crappy pages... <img src="http://www.totalchoicehosting.com/forums/style_emoticons/default/sad.gif" style="vertical-align:middle" emoid=":(" border="0" alt="sad.gif" /><br />Anyway, good luck <img src="http://www.totalchoicehosting.com/forums/style_emoticons/default/smile.gif" style="vertical-align:middle" emoid=":)" border="0" alt="smile.gif" /><!--content-->
Well, it's solved now. It was the doctype causing problems -- evidently my old host had Apache configured differently, but TCH was sending out headers based on the doctype -- which I still had as html 4.0 transitional. Once I changed that, everything's back the way it should be.<br /><br />It wasn't the propagation, evidently, or at least it doesn't seem to have been. But all the nameservers have propagated now, so I guess I can't be sure it <b>wasn't</b> that.<br /><br /><img src="http://www.totalchoicehosting.com/forums/style_emoticons/default/wink.gif" style="vertical-align:middle" emoid=";)" border="0" alt="wink.gif" /> Thanks for your help, both of you!<!--content-->
 
Top