The easier way would be to use
JavaScript instead.
This would generate the link:
Code:
<a href="javascript:history.go(-1)">Go back</a>
If only the user's browser supports
JavaScript and it is not disabled, this will work. Besides this would work also for non-PHP pages like HTML.
If you really want to save the URL in the session variable, you can do this.
Code:
# Read the last page:
$sLastPage = $_SESSION ['sLastServer'] . $_SESSION ['sLastScript'];
$sBack = "<a href='$sLastPage'>Go back</a>";
# Store the current page into the session array:
$_SESSION ['sLastServer'] = $_SERVER ['SERVER_NAME'] # For example, www.yoursite.com
$_SESSION ['sLastScript'] = $_SERVER ['SCRIPT_NAME'] # For example, /news/article.php
$_SESSION ['sLastRequest'] = $_SERVER ['REQUEST_URI'] # For example, /news/article.php?no=123
You just have to think what to display in the virst visit.
Janis