.JSON timestamp to be edited via PHP
Posted: Thu Dec 11, 2014 6:55 pm
I have an interesting project for a client concerning email auto responders. I have completed what I think is most of the work, but I am stuck on how to continue.
Here is the overview:
My client wants to have a server side email auto responder that is activate past a certain time (say 5:00 pm), and inactive the following day (say 8:00 am) - think of an Out of the Office relpy. We all know that Outlook or OWA is capable of this with some custom VBA script, but I need to have this run on the server rather than a client. I have been able to create the email auto response and the associated files in the /.autorespond directory, a PHP script to increment the date/time stamp for the 'start' and 'stop' values, and have this successfully running via a Cron job on my hosted server. Seems to be working great.
However....
The time stamp for the 'start' and 'stop' values located in the .json file is not in a format where I can just increment it with a '+' to change to the next day. What I am in need of is some help on how to edit my code so that I can add one day (+86400) to the current date to the 'start' and 'stop' values in the .json file. This would then prepare the auto responder for the next active period or the next Out of the Office time (5:00 pm - 8:00 am).
This is my .json file with the 'start' and 'stop' values for the email auto responder:
Code:
This is my PHP script that is currently incrementing the 'start' and 'stop' values in the .json file above each time a Cron job is ran on the sever:
Code:
Thanks for any help!
Here is the overview:
My client wants to have a server side email auto responder that is activate past a certain time (say 5:00 pm), and inactive the following day (say 8:00 am) - think of an Out of the Office relpy. We all know that Outlook or OWA is capable of this with some custom VBA script, but I need to have this run on the server rather than a client. I have been able to create the email auto response and the associated files in the /.autorespond directory, a PHP script to increment the date/time stamp for the 'start' and 'stop' values, and have this successfully running via a Cron job on my hosted server. Seems to be working great.
However....
The time stamp for the 'start' and 'stop' values located in the .json file is not in a format where I can just increment it with a '+' to change to the next day. What I am in need of is some help on how to edit my code so that I can add one day (+86400) to the current date to the 'start' and 'stop' values in the .json file. This would then prepare the auto responder for the next active period or the next Out of the Office time (5:00 pm - 8:00 am).
This is my .json file with the 'start' and 'stop' values for the email auto responder:
Code:
Code: Select all
{"stop":1418176354,"start":1418122414,"interval":0}This is my PHP script that is currently incrementing the 'start' and 'stop' values in the .json file above each time a Cron job is ran on the sever:
Code:
Code: Select all
<?php
//Load the file
$contents = file_get_contents('/home/crimmelf/.autorespond/test@crimmelfamily.com.json');
//Decode the JSON data into a PHP array.
$contentsDecoded = json_decode($contents, true);
//Modify the start and stop variable.
$contentsDecoded["start"]+86400;
$contentsDecoded["stop"]+86400;
//Encode the array back into a JSON string.
$json = json_encode($contentsDecoded);
//Save the file.
file_put_contents('/home/crimmelf/.autorespond/test@crimmelfamily.com.json', $json);Thanks for any help!