you could either use sessions, or put the destination in a hidden value of the form.
in PHP, $_SERVER['HTTP_REFERER'] returns the previous page the user came from. this example uses the method of embedding the destination in the form.
login.php
PHP Code:
<?php
// process the login and re-direct if necessary
if ($_POST) {
// login logic goes here
if ($successful login) {
if ($_POST['destination']) {
$destination = $_POST['destination'];
} else {
$destination = "my_default_page.htm";
}
// this forwards the user to the proper page
header("location: ".$destination);
exit;
}
}
?>
<html>
<head>
<title></title>
</head>
<body>
<form action="Login.php" method="post">
<input type="hidden" name="destination" value="<?php echo $_SERVER['HTTP_REFERER']; ?>" />
<label>Username:</label>
<input name="Username" type="text" id="Username">
<br>
<br>
<label>Password:</label>
<input name="Password" type="text" id="Password">
<br>
<br>
<input type="submit" name="Submit" value="Submit">
</form>
</body>
</html>