Member
From: South Africa
Registered: 2006-07-21
Posts: 294
I've been thanked 7 times.
Offline
Can anyone tell me how to send out HTTP headers?
Reason I ask is that the company hosting one of my sites is doing some serious caching. The goold old "pragma" meta tag doesnt work, I still have to refresh the page everytime I add something new to see the content. Seeing as I am basically adding new content at least once a day, this is annoying.
I have heard that if I use an expires HTTP header, it will sort it out. Is it something you put in the header of the code or something you have to do on the server? Also does the header apply to the whole site or can you have different "expires" for different pages?
Please explain this in "stupid person terms" because I've never used HTTP headers before, and what I've found on the internet regarding the subject is quite vague.
Thanks!
Moderator
From: Yorkshire, UK
Registered: 2006-08-19
Posts: 2860
I've been thanked 85 times.
Offline
Member
From: South Africa
Registered: 2006-07-21
Posts: 294
I've been thanked 7 times.
Offline
OK...just had a brief look at that link...will scrutinise later. So I can use PHP to send out the headers, and I assume I can keep the htm extension of the page?
Moderator
From: Yorkshire, UK
Registered: 2006-08-19
Posts: 2860
I've been thanked 85 times.
Offline
you'll have to tell your server to parse htm documents, eg add this to your .htaccess file
AddType application/x-httpd-php .htm .html
Member
From: South Africa
Registered: 2006-07-21
Posts: 294
I've been thanked 7 times.
Offline
Thanks Northie
So let me just confirm this...
If I put this:
at the very top of the page that I want to stop being cached, then it will work?
Is there a way that I can make sure that the headers are being sent out, (besides adding new content & checking) before I go stuffing around with the .htaccess file (because Im on Windows and you have to put something before the dot in order to save a file)
Maybe "AddType application/x-httpd-php .htm .html" is already in the htaccess. What will happen if it's not? Will the page just show up as normal & carry on being cached?
Hope that bit about Windows made sense
Member
From: Pell City, Alabama USA
Registered: 2004-11-17
Posts: 2084
I've been thanked 5 times.
Offline
if you're hosting on windows then you're just hosed because IIS doesn't use .htaccess anyway
find a good host that can switch you to Linux, and then you won't have to worry about the caching thing anyway and you won't have to change your pages or headers or .htaccess unless you just want to
Windows sucks
TombOfTheMutilated.NET - Destroying The Minds of America's Youth Since 2001
Member
From: Pell City, Alabama USA
Registered: 2004-11-17
Posts: 2084
I've been thanked 5 times.
Offline
Roxanne wrote:
Maybe "AddType application/x-httpd-php .htm .html" is already in the htaccess. What will happen if it's not? Will the page just show up as normal & carry on being cached?
what will happen is that the page will not be cached, and the next time you see that page "fresh" - it will have that code appearing at the top of it
when you change .htaccess like he told you, then you will not see the code at the top of the page and your page will not be cached - in other words it will look "fresh"
of course thats assuming you're on Apache where you can change the .htaccess file anyway - if not it really doesn't make a difference
TombOfTheMutilated.NET - Destroying The Minds of America's Youth Since 2001
Member
From: South Africa
Registered: 2006-07-21
Posts: 294
I've been thanked 7 times.
Offline
Mutilated1 wrote:
if you're hosting on windows then you're just hosed because IIS doesn't use .htaccess anyway
find a good host that can switch you to Linux, and then you won't have to worry about the caching thing anyway and you won't have to change your pages or headers or .htaccess unless you just want to
Windows sucks
I'm not hosted on windows, Im using windows. Now in my mind....if I open the .htaccess (in something like notepad, I presume), add the code and click save, surely windows will shout at me?
Maybe my thinking here is painfully wrong...I don't know as I've never done this before.
Member
From: South Africa
Registered: 2006-07-21
Posts: 294
I've been thanked 7 times.
Offline
OK, I managed to create htaccess.txt & then renamed it (via FTP) to .htaccess and now I can't see the file anymore...presumably because I'm using windows, which makes me wonder if there wasn't already an .htaccess file there but I just couldn't see it.
What I want to know is...can I keep the stale date in header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); or do I update it to a slightly newer stale date everytime i change the page?
And do I put the php code even above the doctype?
Moderator
From: Yorkshire, UK
Registered: 2006-08-19
Posts: 2860
I've been thanked 85 times.
Offline
some ftp programmes hide certain files, eg ones with leading dots
search the help for your ftp programme to find out how to show hidden files
for the record - a local windows machine has no problems with file names starting with a dot (especially if you set your folder options to show file extentions
Member
From: Pell City, Alabama USA
Registered: 2004-11-17
Posts: 2084
I've been thanked 5 times.
Offline
you can't see it anymore because the leading . makes it a hidden file on *nix type filesystems
TombOfTheMutilated.NET - Destroying The Minds of America's Youth Since 2001
Member
From: South Africa
Registered: 2006-07-21
Posts: 294
I've been thanked 7 times.
Offline
Well I don't know what planet your PC comes from, but I'm running a local windows machine with file extensions showing and it won't let me save a file as .htaccess. It never has (I tried this long ago & gave up). You can't even rename a file (except in FTP) to .htaccess
Member
From: Pell City, Alabama USA
Registered: 2004-11-17
Posts: 2084
I've been thanked 5 times.
Offline
What I want to know is...can I keep the stale date in header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); or do I update it to a slightly newer stale date everytime i change the page?
personally I would just leave the stale date as it is, but if you wanted to be really cute you could make the PHP change the date for you, just always use yesterdays date or something - probably not worth the trouble unless you just like to do stuff like that
TombOfTheMutilated.NET - Destroying The Minds of America's Youth Since 2001
Member
From: South Africa
Registered: 2006-07-21
Posts: 294
I've been thanked 7 times.
Offline
Mutilated1 wrote:
personally I would just leave the stale date as it is, but if you wanted to be really cute you could make the PHP change the date for you, just always use yesterdays date or something - probably not worth the trouble unless you just like to do stuff like that
Thanks mutilated! I think I'll just leave the date as is...I guess I'm just not that cute! haha ...or sad!
Member
From: Pell City, Alabama USA
Registered: 2004-11-17
Posts: 2084
I've been thanked 5 times.
Offline
Roxane wrote:
Well I don't know what planet your PC comes from, but I'm running a local windows machine with file extensions showing and it won't let me save a file as .htaccess. It never has (I tried this long ago & gave up). You can't even rename a file (except in FTP) to .htaccess
you can't rename a file to .htaccess on windows, and windows won't allow you to create the file with notepad or something, but windows wont have a problem with it if you create the file on *nix and download it to your windows and modify it or save it.
or you could just ditch windows and get something that works right to begin with - its up to you
TombOfTheMutilated.NET - Destroying The Minds of America's Youth Since 2001
Member
From: South Africa
Registered: 2006-07-21
Posts: 294
I've been thanked 7 times.
Offline
ha ha ha...no I think I'll keep my windows for a while yet!
But what is the nix you talk of?
Member
From: San Antonio, TX
Registered: 2006-08-07
Posts: 516
I've been thanked 27 times.
Offline
*nix = Unix / Linix (er... Linux)
In other words real server OS 
Member
From: South Africa
Registered: 2006-07-21
Posts: 294
I've been thanked 7 times.
Offline
I see! I must add that to my jargon page.
Member
From: Southwest, U.S.
Registered: 2006-10-23
Posts: 378
I've been thanked 1 times.
Offline
Roxane wrote:
it won't let me save a file as .htaccess. It never has (I tried this long ago & gave up). You can't even rename a file (except in FTP) to .htaccess
Hope this isn't redundant. I've read where one trick is to prepare the .htaccess as a .txt file (on windows machine), upload it and rename it on the server..
The inverse of M1's manuever?
Member
From: Pell City, Alabama USA
Registered: 2004-11-17
Posts: 2084
I've been thanked 5 times.
Offline
yeah you can do that too
you just can't "create" the file named .htaccess on Windows
Windows will be happy to modify it, but just won't create it with windows tools. I bet you can drop to the command line and do it though.
TombOfTheMutilated.NET - Destroying The Minds of America's Youth Since 2001
| Never |


