Jump to content

[SOLVED] Remember Last Page Visited


hoopplaya4

Recommended Posts

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!

Link to comment
https://forums.phpfreaks.com/topic/144707-solved-remember-last-page-visited/
Share on other sites

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. 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.