Redirecting help

I have this page called explore.php/index.php?random=explore, and there’s this thing where you start a session lasting 24 hours saying that you have only that amount of time to go to these pages (index.php?random=place&cmd=$anyplace). In case you exit that page and go to a different page on the website, how can I make it so that when you go back to index.php?random=explore and the session still exists, it redirects back to the last place you were in index.php?random=place&cmd=$anyplace?