Wrox Home  
Search P2P Archive for: Go

  Return to Index  

javascript_howto thread: Selecting URL based on Server time


Message #1 by aps@i... on Tue, 11 Sep 2001 01:32:30
Sorry, I re-read the question and explicitly says \"time on
the server\".

As far as I know, there is no means for JavaScript to know
the server time; it can read the page modified date/time and
the client browser local time, but not the servers\'s.

To get the server time, it must be used any kind of server
scripting or dynamic html generation. This solution uses PHP to
directly answer with the right page:

** delete any backslashes before quotes -- my mailer is dumb **
----------------------
<?php
// redirecting by server time

// note: there must not be any displayed text before
// the header() call: no echos nor HTML code
// furthermore, do an exit() to guarantee no text after

$time  = strftime(\"%H:%M\");
$limit = \"11:39\";

if ($time < $limit) {
	header(\"Location: http://mywebserver.com/inhours.html\");
	exit;
} else {
	header(\"Location: http://mywebserver.com/outofhours.html\");
	exit;
}
?>
----------------------

The conditional shown divides the day in two periods; to get more ranges
it must be used compound conditionals:

if ($time>=$workdaystart && $time<$workdayend)...

etc.

> -----Original Message-----
 > From: aps@i... [mailto:aps@i...]
 > Sent: 11 September 2001 02:33
 > To: JavaScript HowTo
 > Subject: [javascript_howto] Selecting URL based on Server time
 > 
 > 
 > Hi,
 > 
 > I need to create a solution that will send a user to one of two URLS 
 based 
 > on the time on the server.
 > 
 > My idea is that the user goes to passthru.html which checks the server 
 > time and then passes the user to inhours.html or outofhours.html.
 > 
 > Is this feasible? Any suggestions as to how to craft this? Is ecmascript 
 > the appropriate solution?
 > 
 > Cheers.




------
Ing. Francisco de Jesus Orozco Ruiz
Division de Informatica - CETI, Guadalajara, Mexico
fjor@g...
fjor@m...

  Return to Index