Hey, I just wanted to ask if anybody can show me how i can create a random number that doesnt change for 24hours, I know i could use rand() but that means it changes every refresh, I could also use a cookie and set it to expire in 24hours but is there a way to do it just using php? I need it for my site where the user sees the same message for a day and a new one next day.
Best Solution is Firstly You may create cookie and set expire date is 24 hour and than use rand function with if condition coz their is no other way to known the session base of user.
You could do something like this. srand(date("Ymd")); echo rand(); Each day the date will be different so the random number also will be different. You could do even like this. srand(date("Ymd")); echo rand(1,50);
- first generate the random number and current time. - save the generated number and time on text file. - then read the random number from the text file till the saved time exceeds the 24 hours. if the time exceeds then update the text file info to new random number. if not keep reading the current value from text file.