JRS: In article <
[email protected]>, seen
I have a URL for which I'd like to limit access to by time. For
example,say I have a URL that I don't want accessable on Monday mornings
between 10am-noon and Fri. afternoons between 2-4pm. So when someone clicks
on the URL during those times a message pops up saying somthing like "sorry
we're
closed now etc"
Is this possible? if yes, I'm guessing I'll need somesort of "onclick" for the
href and a script to check the sys time/date ?
Firstly, what do you mean by "Monday"? On the WWW, a day lasts for
about 48 hours, starting at 0000h in or to the Eastward of NZ and
finishing at 2400h somewhere South of the Aleutians.
Probably you mean Monday GMT; or Monday your local time; or Monday in
server's local time; or Monday in some other location; or Monday in your
user's time - and, with all but the first, there is the Summer/Winter
question.
What you ask is, of course, impossible. If I know that URL, I can put
it on a page of my own, and I can click on it at any time I like; even
when I am not connected to the Net. You can, in principle, arrange for
that URL to give a modified 404 response at those times (GMT, server
local, or your local; the user's time is AFAIK unknowable at that
stage). That will need some sort of server-side code.
You can put script in the page itself (which will only work if the user
executes script) to do a pop-up instead of showing the page (unless the
user has a pop-up killer), based on time read from the user's clock and
interpreted as local, or GMT, or elsewhere. The user can defeat this by
setting his clock differently.
You can put the URL on a page of your own, with code such that the click
only works in allowable hours; that's easily defeated
Using user's local time, to determine whether the page should be shown:
T = new Date() // Now
D = T.getDay() // Sun=0..Sat=6
H = T.getHours() // 0..23
Not = D==1 ? H>10 && H<12 : D==5 ? H>14 && H<16 : false
or
HoW = D*24+H
Not = (HoW>34 && HoW<36) || (HoW>134 && HoW<136)
then maybe
if (Not) { DoPoP() ; location.href = ... }
For GMT, use the getUTC functions instead. For remote time, adjust the
UTC to that, see via below.