Jump to content

Modify Headers With Php - Not Working?


lynkali

Recommended Posts

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.

 

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:

 

><?php 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-store, no-cache, must-revalidate");
header("Pragma: no-cache"); ?>

 

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:

 

>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

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

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

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

 

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?

Link to comment
Share on other sites

lynkali,

 

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.

 

Page 52 if you have the book.

 

Here is the code I used and is from the book:

 

><?php
header("cache-control: no-cache, must-revaildate");
header("pragma: no-cache");
header("expires: mon, 26 jul 1997 05:00:00 GMT");
?>

 

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.

 

Scott

Link to comment
Share on other sites

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. :)

 

Thanks!

Link to comment
Share on other sites

I meant to respond to that too.

 

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

Link to comment
Share on other sites

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.

 

PHP says the problem is on line 8 of your script:

>output started at /home/nthulee/public_html/102/hausaufgaben.php:8

 

Check out that line on that file, you'll probably find something there that's outputting some stuff you don't want.

 

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... :(

Anyway, good luck :D

Link to comment
Share on other sites

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.

 

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 wasn't that.

 

:D Thanks for your help, both of you!

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...