You need to conduct proper debugging techniques.
Firstly if there are no error messages then break the code down in your head.
I tested this code and I know the 'fopen' part works. How do I know?
Well
$fp = fopen( "test.txt", "w" );
Tells my server assign the following instructions to variable $fp: Open file named 'test.txt', wipe out the contents then place the ifle pointer in the file. I.E. 'Overwrite'. If this file does not exist then attempt to create it.
It did not exist so it created it perfectly well.
$result = file_get_contents( "test.txt" );
In order to test this line, I opened the txt file and wrote something in it. I then copy/pasted the above 2 lines of code into a new page (fresh) and typed:
echo $result;
Much like you did, but yours wasn't working so maybe your code did something to the contents to stop it echo'ing anything?
(NOTE: I had to change the "w" to "a" because in my test code, when opening the text file, it deletes it's contents then echo's it. It would echo nothign then...so I changed the "w" to "a" just to test the file retrieval.
So...I type in FOO into the text.txt file. Look, it works!:
I will now be missing the entire IF statement and test the fwrite() function. I have changed the 'a' back to 'w' to test the code as a whole. I now have the following code on it's own
$fp = fopen( "test.txt", "w" );
fwrite( $fp, "2" );
And it works! Now, to further test this code, I have replaced the '2' with '1' to test the 'w' part of the fopen function. Once again - it works!
So now we have whittled this program down to your iffy IF statement.
You say nothing is written to your test.txt file? We can now be 100% certain now that it is because your IF statement is returning FALSE and will not write anything. CHeck the criteria of your IF statement.
if(date('H')==13 AND date('i')==17)
This means that the page has to be prcoessed within the 60 second zone of 13:17 for the IF statement to return TRUE and fwrite the '2' to your 'test.txt' file.
Are you sure that the page is being processed within this time? Baring in mind that the time will not go from the user's computer but from the server's computer...
For the last time I am testing this code for the time. I can verify the time as my computer IS the server so I can see the time to validate it :p
I use the full code shown below. RThe time has been changed to the present time of testing, '23:02'.
$fp = fopen( "test.txt", "w" );
$result = file_get_contents( "test.txt" );
if(date('H')==13 AND date('i')==17)
{
fwrite( $fp, "2" );
}
print $result;
Okay I had mixed test results with the full code. It wrote tot he text file but did not PRINT the $result. It is outside the IF statement so regardless of wether the IF statement is TRUE, it should echo the file contents.
So - the faulty part of the script I have found (and you could have found if you debugged properlly) is the PRINT part at the bottom of the script.
Earlier on we tested the file_get_contents so there must be a problem with where the variable $result is defined. Or maybe not...to be honest I cannot make it out right now.
However, I can see that the $result variable is defined before any changes are made. Is this what you wish to do? Show the contents of the text file BEFORE and changes were made? If you wanted to show the contents AFTER the changes then this is definately not working.