I have a “Session” Table below:
SessionId(Auto) SessionName SessionDate SessionTime Duration Active
1 AASEA 21-09-2012 09:00:00 01:00:00 1
2 SDERF 11-09-2012 10:00:00 01:00:00 1
3 DERSD 30-11-2012 12:00:00 01:30:00 1
Now what I want to do is use CRON to be able to set the Sessions above to “Active” – 0 if the Session was held eaxactly week before 21/10/2012 or earlier of the current year. So in Session Table above, it should make the first 2 rows inactive by changing “Active” to 0. The third row won’t obviously change as its start date is later on. So that session won’t become automatically inactive till October 21st 2013.
So I want to know as that I havn’t used CRON before and this is a delicate task as it needs to be tested to ensure it works, does somebody know how to write the php/CRON script so that it does the following:
- Sets the “Active” value to 0 for all sessions which start date is exactly a week or before the date of 21st October of the current year?
- It must be able to know what the current year is automatically
- This procedure happens yearly every 21st October of each year
Thanks
Write this script in a php file and save it somewhere in the application directly.
Now you need to login to your hosting site – cPanel and access CRON jobs. There you need to set up a new CRON job.This is a tutorial of how to set up a cron job – http://www.youtube.com/watch?v=0OBvGbyj15Q
Just replace the url used in the video with the script written above and it should work fine for you. Make sure you replace the credentials and the database.
You can set the cron job on 21st October every year or can run it everyday. Our script anyways validates the date, so no problem if you run the cron job every day also. This is not an expensive query and so the resources used are bare minimum.