Can you think of a method to stop a webpage opening before a set time?

I have a little webpage for homework. I have a javscript which disables the send button at a certain time. This effectively switches the webpage off.

At the moment, I use another javascript to block the link to the latest webpage until a certain time. This stops the webpage from being opened via the link.

However, the latest webpage is not really blocked. It can be opened.

It is a bit inconvenient to only upload just before the time to open the homework. I like to upload the pages on the weekend.

Can you think of a way to prevent a webpage opening before a set time?

Some kind of php chronjob on the server? Maybe something that will copy the webpage into the correct folder at a set time? Or unscramble the name?

What prevents me from just enabling the send button?

Regarding preventing a webpage from opening, just check the publish datetime on the server side and present a “not available until datetime” page if it isnt supposed to be published yet. Remember to check time zone on the server so you know you and your server agree on what time it is though ^^

I would not know. someone told me it was trivial to change the javascript. I don’t know how. As far as I know, I am the only person with write permissions on my webhost. But I am not a hacker or even slightly knowledgeable about these things.

How would I check the publish datetime on the server?

The best suggestion I have yet is upload the file, set its permissions to 600, then use at to chmod 644 | at 2pm, for example

if($_SERVER['REQUEST_METHOD'] == 'POST') {
    // check the submission time
    $date = new DateTime();
    $hr = $date->format('H');
   // if time before 2pm disallow
   //  will work for 2pm until 11:59pm of that day
    if($hr < 14) {
        echo "Cannot submit before 2pm";
        exit;
    }
    // processing code if after 2pm

}
1 Like

Thanks, that is simple but effective!

One caveat that was already mentioned, you need to ensure that your server is on your local time, or that will not work. You can set that value globally or on a page specific instance however using this https://www.w3schools.com/php/func_date_default_timezone_set.asp

The javascript you talk about runs in the browser and everything in the browser is editable by the user. So whatever you do there security wise should not be considered real security, but it can still be useful features for the user. Ie it’s a much better user experience if you have a live countdown on the webpage, or live validation of form fields.

The server should never trust anything the client says so any real security checks (if current time > allowed time) should be done server side.

1 Like

Thanks, both of you.

The timezone thing may be a headache. I’ll try and get ‘at’ to work. With that, I can set the time and date on the server, no need for javascript.

But, for now, at is not working.

myusername@sg3plcpnl0194 [~/public_html/18BE]$ date
2019年 12月 16日 星期一 12:53:59 MST
myusername@sg3plcpnl0194 [~/public_html/18BE]$ echo “chmod 644 18BEtestAT.html” | at 1pm 2019-12-16
cannot set egid: Operation not permittedmyusername@sg3plcpnl0194 [~/public_html/18BE]$

I think you are misunderstanding how I am saying to do it.

<?php

date_default_timezone_set("Europe/Moscow");
$date = new DateTime();
echo $date->format("Y-M-d H:i:s");
echo "\n\n";
date_default_timezone_set("America/New_York");
$date = new DateTime();
echo $date->format("Y-M-d H:i:s");

This applied to your code, means that you can set the timezone properly for this script to run or not.

1 Like
Sponsor our Newsletter | Privacy Policy | Terms of Service