How to return to last visited page of the website during next visit to the website?
The website do not have a login. But it is a continous funnel of pages from 1-15, and pages datas are stored in sessions. So need to return to the last visited page without losing the page datas
You could do this with cookies, both in the browser - and on the server.
PHP Example:
<?php
session_start();
if(!isset($_SESSION['checked_last_page'])){
//get last page visited
$lastPage = $_COOKIE['last_page'];
//expire cookie
setcookie('last_page', null, time() - 1000);
//forward to last page
header('Location: ' . $_COOKIE['last_page']);
exit(0);
}
//prevent doing redirect every time
$_SESSION['checked_last_page'] = true;
//set the last page in a cookie
setcookie('last_page', $_SERVER['REQUEST_URI'], time() + 3600 * 24 * 31);
?>
You could do this with javascript too. In that case you'd have to set an additional cookie to mimic the behavior of a session cookie. This will ensure you don't do the redirect on page request that are part of an active session. (IE: The user visits a page and gets redirected - and gets redirected again)
Please let me know if you need a js example.