473,799 Members | 3,017 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Script to Tell Tell Time then Limit by it?

Hi,
I'm hoping someone can help me with this.

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 ?

TIA,
Mike
Jul 20 '05 #1
17 4889
"Mike A" wrote on 15/11/2003:
Hi,
I'm hoping someone can help me with this.

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 ?


Be aware that it is much better to do this server-side. Many users
routinely disable JavaScript, so your restrictions will be ignored.
However, if your host doesn't allow server-side processing, you might
do something like:

// Returns boolean false if the website
// is closed, true otherwise
// All comparisons are done using UTC (GMT).
function isAccessable()
{
var now = new Date(); // Get current time and date

select( now.getUTCDay() )
{
case 1: // Monday
// Time between 10:00:00 and 11:59:59 UTC
if(( 10 <= now.getUTCHours () ) && ( 12 > now.getUTCHours () ))
return false;
break;
case 5: // Friday
// Time between 14:00:00 and 15:59:59 UTC
if(( 14 <= now.getUTCHours () ) && ( 16 > now.getUTCHours () ))
return false;
break;
}
window.alert(
'Sorry, this site is closed between the following times (GMT):\n'
+ '\n10:00 and 12:00 on Mondays'
+ '\n14:00 and 16:00 on Fridays' );
return true;
}

....and use a link like:

<A href="my-time-restricted-page.html"
onclick="return !isClosed();">E nter</A>

One last point: as I've learnt recently, operations involving dates
can be very tricky. Although you shouldn't have any trouble here (the
comparisons are quite simple in the example above), you might want to
take a look at the 'Date and Time' section of Dr J R Stockton's
JavaScript Index (http://www.merlyn.demon.co.uk/js-index.htm).

Hope that helps,

Mike

--
Michael Winter
M.Winter@[no-spam]blueyonder.co.u k (remove [no-spam] to reply)
Jul 20 '05 #2
Mike A hu kiteb:
Hi,
I'm hoping someone can help me with this.

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 ?


How do you plan to account for different time zones? How do you plan to
account for computers whose clocks are set incorectly?
--
--
Fabian
Visit my website often and for long periods!
http://www.lajzar.co.uk

Jul 20 '05 #3
JRS: In article <15************ **************@ posting.google. com>, seen
in news:comp.lang. javascript, Mike A <mi***@capital. net> posted at Sat,
15 Nov 2003 06:08:49 :-
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.

--
© John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v4.00 IE 4 ©
<URL:http://jibbering.com/faq/> Jim Ley's FAQ for news:comp.lang. javascript
<URL:http://www.merlyn.demo n.co.uk/js-index.htm> JS maths, dates, sources.
<URL:http://www.merlyn.demo n.co.uk/> TP/BP/Delphi/JS/&c., FAQ topics, links.
Jul 20 '05 #4
JRS: In article <JM************ *******@news-text.cableinet. net>, seen
in news:comp.lang. javascript, Michael Winter <M.Winter@[no-spam]> posted
at Sat, 15 Nov 2003 15:39:21 :-
"Mike A" wrote on 15/11/2003:
I have a URL for which I'd like to limit access to by time.

Be aware that it is much better to do this server-side. Many users
routinely disable JavaScript, so your restrictions will be ignored.
It is possible to have a lead-in page which uses javascript to call the
real page provided that the time is right. If the lead-in page appends
the time_t of call to the URL, and the real page checks early in loading
that the present time is no earlier than that and not much later
aborting otherwise, modest security is obtained. The time can be
encoded in Base 36 and shuffled, to make the situation obscure. Non-JS
users then do not see the real page, and cheating is non-trivial.
select( now.getUTCDay() )
I'm not familiar with that use of "select"; I'd use "switch".
// Time between 10:00:00 and 11:59:59 UTC
Not really. Time >=10h & <12h.
if(( 10 <= now.getUTCHours () ) && ( 12 > now.getUTCHours () )) window.alert(
'Sorry, this site is closed between the following times (GMT):\n'
+ '\n10:00 and 12:00 on Mondays'
+ '\n14:00 and 16:00 on Fridays' );
return true;
}


AFAICS, that alert is given when the site is accessible.

On the whole, only tested code is worth posting.

--
© John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v4.00 IE 4 ©
<URL:http://jibbering.com/faq/> Jim Ley's FAQ for news:comp.lang. javascript
<URL:http://www.merlyn.demo n.co.uk/js-index.htm> JS maths, dates, sources.
<URL:http://www.merlyn.demo n.co.uk/> TP/BP/Delphi/JS/&c., FAQ topics, links.
Jul 20 '05 #5
Dr John Stockton wrote on 16 Nov 2003:
JRS: In article
<JM************ *******@news-text.cableinet. net>, seen in
news:comp.lang. javascript, Michael Winter <M.Winter@[no-spam]>
posted at Sat, 15 Nov 2003 15:39:21 :-
"Mike A" wrote on 15/11/2003:

I have a URL for which I'd like to limit access to by time.
Be aware that it is much better to do this server-side. Many
users routinely disable JavaScript, so your restrictions will be
ignored.


It is possible to have a lead-in page which uses javascript to
call the real page provided that the time is right. If the
lead-in page appends the time_t of call to the URL, and the real
page checks early in loading that the present time is no earlier
than that and not much later aborting otherwise, modest security
is obtained. The time can be encoded in Base 36 and shuffled,
to make the situation obscure. Non-JS users then do not see the
real page, and cheating is non-trivial.
select( now.getUTCDay() )


I'm not familiar with that use of "select"; I'd use "switch".


Simple confusion between languages.
// Time between 10:00:00 and 11:59:59 UTC


Not really. Time >=10h & <12h.


That is, for all intents and purposes, the same thing. If the hour
is, or is after 10, and at any time during the 11th hour, it is as I
described (though more correctly 11:59:59.999) and evaluated below.
if(( 10 <= now.getUTCHours () ) && ( 12 > now.getUTCHours ()
))

window.alert(
'Sorry, this site is closed between the following times
(GMT):\n' + '\n10:00 and 12:00 on Mondays'
+ '\n14:00 and 16:00 on Fridays' );
return true;
}


AFAICS, that alert is given when the site is accessible.


You would be correct. If you check the HTML snippet I included, the
function name is 'isClosed()'. I thought that I'd reverse the logic
to make it easier to use, but I obviously forgot to negate the
comparisons. Each if statement should be corrected to:

if( !( <original expression )) { statements }

Thank you for bringing attention to my lapse in concentration: I've
informed the original poster by e-mail (he contacted me after I made
my post).

Mike

--
Michael Winter
M.Winter@[no-spam]blueyonder.co.u k (remove [no-spam] to reply)
Jul 20 '05 #6
I really did make a pigs ear of my original code: all returns need to
have their values inverted too.

I truly am sorry about this. I will make sure that I review and test
any code in my responses thoroughly. I will refrain from posting
further unless I am as certain as I can be about the validity of the
advice or suggestions I give.

Sincerly,
Michael Winter
Jul 20 '05 #7
Ok, As a newbie, I'll have to ask as I'm now totally confused.
I'm trying to edit Michael Winter's original code with the edits
he suggested (in a previous post) with no luck, would someone
be kind and assist?

TIA,
Mike
Jul 20 '05 #8
Mike A wrote on 17 Nov 2003:
Ok, As a newbie, I'll have to ask as I'm now totally confused.
I'm trying to edit Michael Winter's original code with the edits
he suggested (in a previous post) with no luck, would someone
be kind and assist?

TIA,
Mike

Unless someone can find any more errors (I did boundary test it) or I
overlooked something, this should be fine (under Opera 7.22 and IE 6,
at least). Any comments relating to date operations are also welcome.
The script:

function isAccessable()
{
var now = new Date(); // Get current time and date

switch( now.getUTCDay() )
{
case 1: // Monday
// Time between 10:00:00 and 11:59:59.999 UTC
if( !(( 10 <= now.getUTCHours () ) && ( now.getUTCHours () < 12 )))
return true;
break;
case 5: // Friday
// Time between 14:00:00 and 15:59:59.999 UTC
if( !(( 14 <= now.getUTCHours () ) && ( now.getUTCHours () < 16 )))
return true;
break;
}
window.alert(
'Sorry, this site is closed between the following times (GMT):\n'
+ '\n10:00 and 12:00 on Mondays'
+ '\n14:00 and 16:00 on Fridays' );
return false;
}
The HTML:

<A href="my-time-dependant-page.html"
onclick="return isAccessable(); ">Enter</A>

I really am sorry about the mix up. Be warned: when entering a month,
remember that they're zero based (0 - January, 1 - February, etc).

Also remember to convert all times to UTC (GMT) so the comparisons
are applicable all over the world.

Mike

--
Michael Winter
M.Winter@[no-spam]blueyonder.co.u k (remove [no-spam] to reply)
Jul 20 '05 #9
JRS: In article <15************ **************@ posting.google. com>, seen
in news:comp.lang. javascript, Mike A <mi***@capital. net> posted at Mon,
17 Nov 2003 09:49:58 :-
Ok, As a newbie, I'll have to ask as I'm now totally confused.
I'm trying to edit Michael Winter's original code with the edits
he suggested (in a previous post) with no luck, would someone
be kind and assist?


That may be sub-optimal.

To the article to which the above is a response, add :

or
HoW = D*100 + H
Not = (HoW>110 && HoW<112) || (HoW>514 && HoW<516)

or
HoW = D + H/100
Not = (HoW>1.10 && HoW<1.12) || (HoW>5.14 && HoW<5.16)

Note that the numbers are of the form <Day-of-JS-Week><Hours>; cf.
<URL:http://www.merlyn.demo n.co.uk/js-date1.htm#DC> and
<URL:http://www.merlyn.demo n.co.uk/js-date1.htm#TCp>.

--
© John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v4.00 IE 4 ©
<URL:http://jibbering.com/faq/> Jim Ley's FAQ for news:comp.lang. javascript
<URL:http://www.merlyn.demo n.co.uk/js-index.htm> JS maths, dates, sources.
<URL:http://www.merlyn.demo n.co.uk/> TP/BP/Delphi/JS/&c., FAQ topics, links.
Jul 20 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
3666
by: Damien | last post by:
Hello to all, I've written a script that take quite a long time to execute (email sending). Last time I ran it, PHP gave me a "execution time limit exceeded" (or something like that), so I changed the value in php.ini. Now, the questions are : - How can I make sure I'm not going to have problems when execution time lengthens still ? I'm afraid to set too high a time limit in case other scripts run astray. - Can I "break" the job into...
6
4170
by: Jeffrey Silverman | last post by:
Hi, all. Sorry, first off, for the kidna weird selection of crossposted groups, but this question touches on aspects of discussion in each of the groups. So I have a group of around 500 email addresses to which I would like to send a mass email occasionally. The group will never be much larger than 500 email addresses and will occasionally be about half that size. I have written a simple HTML interface and PHP backend to process the...
0
6031
by: Will Seay | last post by:
At the end of this message I've pasted a script we're trying to modify slightly. I don't believe it is VBscript or javascript but these are the closest groups I could find with my limited programming knowledge. Basically, we are trying to add a few lines to this script that will execute a few shell commands (see comments at the very end of the code). We think this may be ActionScript2 but aren't sure. If you can offer any help, or know...
4
1295
by: R.Meijer | last post by:
Hi, I've been busy with an experimental script, and I can't seem to see what is wrong with it, can somebody tell me? Here it is: a = 0 b = 1 mainloop = 1 print "Welcome to pyFibo"
6
1768
by: Justice | last post by:
Just moved site to different web server. Previously no problems. Now, the script will time out after 90 minutes. I've set set_time_limit(0) but no effect. Any ideas? John
11
24179
by: www.MessageMazes.com | last post by:
I sometimes get this error after about 60 seconds of "waiting for mazes.com" (but when the page works, it usually loads in less than 12 seconds). > Active Server Pages error 'ASP 0113' > Script timed out > /asp-maze/amazingtest.asp > The maximum amount of time for a script to execute was exceeded. You can > change this limit by specifying a new value for the property Server.ScriptTimeout > or by changing the value in the IIS...
3
3976
by: Hugo Lefebvre | last post by:
Is there a maximum number of emails CDONTS can handle in an asp script? I have different questions about this. Question1: example1: set objSendMail = createobject("CDONTS.NewMail") ...... objSendMail.To = emailto
5
3488
by: This | last post by:
I have a pretty basic emailing script that sends a relatively small number (150) of html emails. The emails are compiled, personalised from a mysql db subscribers list, and sent using mail() - after sending, a small summary html page is sent to the user with number sent, time taken and a simple navigation choice. Up to about 100 emails it all works fine - this takes the server about 27 secs . Any more than that and although the emails are...
1
47492
KevinADC
by: KevinADC | last post by:
Note: You may skip to the end of the article if all you want is the perl code. Introduction Many websites have a form or a link you can use to download a file. You click a form button or click on a link and after a moment or two a file download dialog box pops-up in your web browser and prompts you for some instructions, such as “open” or “save“. I’m going to show you how to do that using a perl script. What You Need Any recent...
0
9685
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10473
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10249
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10025
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6804
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5461
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5584
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4138
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2937
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.