Hello....

I'm not sure if this is possible or not ...

On my page.. index page.. I've created a form button..
Ok.. Let say... depends on the system time (server) .. whenever
my client click more than specific time.. let's say (more than 0800 hours server time).. it will directly go to specific page..

I hope your guys get it ...

Thanks in advance..

Dani AI

Generated

Your posted client-side snippet uses the browser clock, so it will follow whatever the visitor's machine reports (and it fails if JavaScript is disabled). As hints, if you truly want "server time" to decide which page a click goes to, do the check on the server when the form is submitted. That guarantees consistent behavior and avoids client-side clock drift or disabled JS.

Suggested workflow

  1. Have the form submit to a server endpoint (so the browser always talks to your server).
  2. On the server, read the server clock, compare it to your threshold (08:00 in your server timezone or UTC as you prefer).
  3. If the condition is met, respond with an HTTP redirect to the target page; otherwise handle the normal flow. Always stop output after issuing the redirect.

Minimal PHP example (server-side handler):

// process.php (target of the form)
date_default_timezone_set('UTC'); // or set to your server timezone
$now = new DateTime('now');
$threshold = new DateTime('08:00');
if ($now >= $threshold) {
    header('Location: /after0800.php', true, 303); // 303 after POST to avoid resubmit
    exit;
}
// continue normal processing

Notes and gotchas

  • Use a proper timezone (server config or DateTimeZone) to avoid DST/offset surprises.
  • Send a 303 after a POST to avoid browser resubmit prompts; send 302/307 as appropriate for GETs. MDN has a good summary of redirection semantics (see Web/HTTP/Redirections).
  • Never emit output before calling header() in PHP; follow with exit. See the PHP header() docs for details.
  • If you want snappier UX, you can add client-side detection for speed, but always enforce the redirect server-side as the final authority and validate any redirect targets to avoid open-redirect vulnerabilities.

Recommended Answers

All 2 Replies

ok, I just got this.. it can be done with something like this..

and Javascript is totally new for me..

<html>
<body>

<script type="text/javascript">
var d = new Date();
var time = d.getHours();

if (time < ) 
  {
  document.write("<b>Good morning</b>");
  }
</script>

<p>This example demonstrates the If statement.</p>
<p>If the time on your browser is less than 10, you will get a "Good morning" greeting.</p>

</body>
</html>

Instead of saying good morning ... I want this page will directly go to different page..

There are plenty of examples on line on how to do this, but the only concern I have is that you are depending on the fact that javascript is going to be enabled for the user's browser. this is not always the case. If you are using a server side scripting language such as php or asp.net, it will be easier to handle and you will guarantee that this will work 100% of the time. However, if you are writing your page in pure html, you will need to depend on javascript.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.