hoopplaya4 Posted February 11, 2009 Share Posted February 11, 2009 Hi All, I'm using cookies to "remember" users (after they've closed the browser) and log them back in. However, I'd like to add/set a cookie to where, when users close the browser, but them open it again, it will bring them back to last page they visited on my website. Any idea on the logic of how do this? Right now, I'm kinda doing something like: <?php session_start(); $expire = time() + 1728000; setcookie('lastvisit', "page1", $expire, "/"); if($_COOKIE['lastvisit'] == "page2") { print" <script> window.location=\"page2.php\" </script> "; } However, my logic kinda gets stuck in a loop, where I can't overwrite the last cookie. Any ideas on how to achieve this? Thanks! Quote Link to comment Share on other sites More sharing options...
5kyy8lu3 Posted February 11, 2009 Share Posted February 11, 2009 Hi All, I'm using cookies to "remember" users (after they've closed the browser) and log them back in. However, I'd like to add/set a cookie to where, when users close the browser, but them open it again, it will bring them back to last page they visited on my website. Any idea on the logic of how do this? Right now, I'm kinda doing something like: <?php session_start(); $expire = time() + 1728000; setcookie('lastvisit', "page1", $expire, "/"); if($_COOKIE['lastvisit'] == "page2") { print" <script> window.location=\"page2.php\" </script> "; } However, my logic kinda gets stuck in a loop, where I can't overwrite the last cookie. Any ideas on how to achieve this? Thanks! not sure if it's reasonable to do so but you could easily make a new column in the username/pwd table named 'last_page' and just save the name of the last page they were on, and have each page update that column to that page, so you don't have to mess with cookies. so... if they click on the page 'news.php' somewhere in the header of that page it saves 'news.php' to the 'last_page' column, so when they log back in, it sends them to $loc = '/the/document/path/' . $last_visit; just one method of doing it. Quote Link to comment Share on other sites More sharing options...
hoopplaya4 Posted February 11, 2009 Author Share Posted February 11, 2009 Thanks for the reply. That's a good start, and something I'll definitely keep in mind. Any other ideas that might be worth implementing? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.