I have a query to display a random background image
SELECT *
FROM page_backgrounds
ORDER BY RAND()
This is indeed gives me a random background image but as well when I go from page to page within the website. What I’m actually looking for is a way to have a random background per visit. What is the best way to do that?
I’d suggest you store the image that you’ve assigned as background in a session. Then it’s a matter of deciding when you make a session expire, and checking whether the user’s session has an existing background image, and if not, load a random one and assign it to the user’s session.
From what I can see this code gets executed each page load, and I see no check whether the session variable for ‘random_photo’ exists. What you want is probably something like:
disclaimer: I do not know PHP, consider this pseudocode