joad wrote:Many thanks Xager, the help's much appreciated. One thing, where it says $_SESSION['current_page'] = "/page/you/are/on/now.php";
the current page will not always be the same - in other words, from any page on the website, they should be able to go back to the previous page they were viewing.
You have to change /page/you/are/on/now.php in each document.
You could do the following:
$_SESSION['current_page'] = $_SERVER['REQUEST_URI'];
Let's say your're on http://mysite.com/page.php?page=test
Then $SERVER['REQUEST_URI'] would return "/page.php?page=test"
Here a refined version:
function updateCurrentPage(){
if(isset($_SESSION['current_page'])){
$_SESSION['page_before'] = $_SESSION['current_page'];
}
else{
if($_SESSION['HTTP_REFERER'] != ""){
$_SESSION['page_before'] = $_SESSION['HTTP_REFERER'];
}
else{
$_SESSION['page_before'] = "/index.php";
}
}
$_SESSION['current_page'] = $_SERVER['REQUEST_URI'];
}
Put this in a separate document and do the following on each page:
include("/path/document.php");
updateCurrentPage();
random code here
echo('<a href="' . $_SESSION['page_before'] . '">Go back</a>');