I have a php function that reads a line (random message) from a file and displays it on my web page. It displays a new message every time I click refresh, but I want it to display the message for a day (it should change at midnight). Is it possible to do it with another function, implying my database? Or with a JS function?
CodePudding user response:
You have multiple possibilities :
- Create a file with only one line every day taken from the other file
- Create a cron who will be executed ad midnight who will get a random message and set it in database or cache.
- If you want a different message per people but persist one day, you can use the local storage of the visitor to store the message with the current date and if the date stored is different from the current date, you change it.
CodePudding user response:
- get total lines from your file
- Use a database or file and store a random number daily.
- Use that number to read a random message from the file.
- Use cron to update random numbers at midnight in your database or file.
So, for 24 hours the same message will be displayed.