每晚计算一个数字

For an project in Visual Basic, I need a site (script) that every night reset the number on the site to 1.

So if it is 00:00 then it will reset the number on the page to 1, and repeat that every day.

I tried this code :

<?php
//Kijken of het 00:00 is
if(date('H') == '00'){
//Het is 00:00 uur dus ik geef 1 weer
  $tijd = 1;
} else {
//Het is nog geen 00:00 uur dus ik geef 0.
  $tijd = 0; 
}
if($_GET["tijd"]){
    $tijd = $_GET["tijd"];
}

//het bestand schrijven
$file = 'nulofeen.txt';
// Open the file to get existing content
$current = file_get_contents($file);
// Append a new person to the file
$current = $tijd;
// Write the contents back to the file
file_put_contents($file, $current);

//Open het bestand
$file = file("nulofeen.txt");
//Lees de laaste regel uit
for ($i = count($file)-1; $i < count($file); $i++) {
//echo de laaste regel
  echo $file[$i];
}
?>

But that won't work it wont't reset anything.

You need to setup a Cron job. This will run your script every night, and from there you can store the number 1 in your file. Also, no need to run the time check, just have the cron run at midnight.

Cron syntax, in case you're unaware:

00 00 * * * php path/to/your/script.php

That will run a file every morning at midnight. This assumes you're using PHP, and that you are running on linux.

The OP brought up another point in his comments, this may help future readers. Other people than yourself will be viewing your site, so you need a way to automatically load in the current number value on page load. To do this, either setup a database and update the number to be shown at midnight, or read from the text file (see OP) on each page load.

create a cronjob that will run every night at midnight:

00 0 * * 0,1,2,3,4,5,6 php /path/to/your/script.php

this script will rewrite to the file "1" every time its run

<?php

$file_name = "test.txt";
$fh = fopen($file_path, "w") or die("cant open file");
$toFile = "1";
fwrite($fh, $toFile);
fclose($fh);

?>