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
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. 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.