Home > database >  How to display a different message read from a file every day of the week in php?
How to display a different message read from a file every day of the week in php?

Time:02-11

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 :

  1. Create a file with only one line every day taken from the other file
  2. Create a cron who will be executed ad midnight who will get a random message and set it in database or cache.
  3. 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:

  1. get total lines from your file
  2. Use a database or file and store a random number daily.
  3. Use that number to read a random message from the file.
  4. Use cron to update random numbers at midnight in your database or file.

So, for 24 hours the same message will be displayed.

  • Related