Log in

View Full Version : cache only for 8 hours



yitschak
07-29-2010, 02:45 PM
bs"d

Hello

I want that the brower will cache my site only for 8 hours
so if someone get in tommorow the page will load from the server and not from the cache...

for that I'll use: <META HTTP-EQUIV="EXPIRES" CONTENT=mon, 27 sep 2010 14:30:00 GMT>

As you understand I need that the date in the tag will be dynamically...
but for that I need a script that I don't know to write... or to find one in the internet..

can someone plzz help me?

thanks
yitschak :)

yitschak
07-29-2010, 02:51 PM
This messege is only to subscribe the messege for me...

ignore it

sorry =]

djr33
07-29-2010, 08:50 PM
You can use PHP and the function date() to generate this. Do you have PHP available?

yitschak
08-04-2010, 01:52 PM
All I know that this is a Microsoft Server..
and I was told that the server that I'm using not supporting PHP

But I wanna check this...
can you write me some code that I can use to check if PHP is supported?

thx
yitschak

yitschak
08-04-2010, 02:12 PM
I guess PHP is not supported, because I put a file named phpinfo.php on my server
which contained the next code:

<?php
phpinfo();
?>

and I got an Error: "The page cannot be found"

djr33
08-05-2010, 04:48 AM
You shouldn't get a 404 ("not found") error for a PHP file on a server that doesn't support PHP. Instead, it should show up blank, show up as html (so you read "<?.....") or download as a file-- this probably all depends on the browser. So maybe you typed the wrong URL? Maybe PHP does work...
It's possible that your server is configured to ignore .php, but that's a very odd behavior...

If it's a microsoft server it's likely that you do not have PHP, but it's also likely that you do have ASP, microsoft's serverside language that does basically the same thing. Personally I use PHP, but there's no reason you can't use ASP in the same way-- I can't tell you the specifics though. It shouldn't be hard if you search for "ASP date".

yitschak
08-06-2010, 11:25 AM
This information is very helpful...

but, do I really have to change the extention of all the pages in my site to aspx just for one-line script?

is there another way?

thanks! =]

djr33
08-06-2010, 03:55 PM
By default, .htm and .html are processed as HTML. So, yes, you will need to do something to change them to .php or .asp, or whatever other language you want to use if it isn't just HTML.

There are, however, a few different ways you can approach this:

1. You can manually rename all files. While this sounds like it's a lot of work, it will make everything simpler in the end. Remember this also means you need to change all hrefs that link to these pages. (It's possible to automate this process by running a script that automatically converts .htm to .php if you want, but planning that and executing it can take longer than just doing it manually.)

2. You can tell your server to treat .htm as PHP file. Basically this is just a different setting than the default and it will pretend that ".htm" means PHP. This is very easy, done through .htaccess, but it is a weird way to fix the problem: .htm is NOT PHP, so why are you telling your server to treat it like it is? There are two main reasons not to do this: 1) it means that ALL .htm files will be run as .php (less efficient); 2) it will be confusing for later updates: why are the .htm files magically running PHP code? It's unexpected.

3. You could use mod_rewrite (.htaccess) to automatically switch all (or some) .htm extensions to .php. This wouldn't fix all of the issues with it, so you would still need to rename all of your files. But this would mean that links to ".htm" would 1) appear to the user as .htm still (even though the server is using a .php page) and 2) the old .htm links would not be broken, so it would save you time changing all pages that link to the updated pages, just not the time changing the extensions. I don't really recommend this approach, but it would be helpful.... mostly it's just a lot of work and confusing...

yitschak
08-08-2010, 05:55 AM
I guess I'll do the manual change...

Good day!!
and Thx!! =]

yitschak
08-09-2010, 10:38 AM
I wrote the next code:

<script type="text/vbscript">//<![CDATA[
<!--
dim dateNow
dim str
dim daysOfWeek(6)
daysOfWeek(0)="Sun"
daysOfWeek(1)="Mon"
daysOfWeek(2)="Tue"
daysOfWeek(3)="Wed"
daysOfWeek(4)="Thu"
daysOfWeek(5)="Fri"
daysOfWeek(6)="Sat"
dim monthsNames(11)
monthsNames(0)="Jan"
monthsNames(1)="Feb"
monthsNames(2)="Mar"
monthsNames(3)="Apr"
monthsNames(4)="May"
monthsNames(5)="Jun"
monthsNames(6)="Jul"
monthsNames(7)="Aug"
monthsNames(8)="Sep"
monthsNames(9)="Oct"
monthsNames(10)="Nov"
monthsNames(11)="Dec"
dateNow=dateadd("h", -1, Now) //1 hour forward because I took 2 hours back for GMT
dim dayOfMonth
dayOfMonth=CStr(Day(dateNow))
if Len(dayOfMonth)=1 Then dayOfMonth="0"+dayOfMonth

str=CStr(daysOfWeek(Weekday(dateNow)))+", "+dayOfMonth+" "+monthsNames(Month(dateNow))+" "+CStr(Year(dateNow))+" "+CStr(Time)+" GMT"
document.write("<META HTTP-EQUIV=""EXPIRES"" CONTENT="+str+">")
-->
//]]></script>


When I checked the cache there was no expiration date...
but, I guess the script is ok...

because even when I wrote the meta tag manually for now to check if it works it didn't show any expiration date....

so I guess somthing wrong with the meta atg and not in the script

good day