if you say that the page they came from is the webpage variable. So say you are on the page:
site.php?webpage=main
then the link to the login would be:
site.php?webpage=login&returnto=$webpage
Then on the login poage you would do something like this:
/ do the login stuff ... /
header("Location: site.php?webpage=$returnto");
By the way, if you are doing user authentication you my want to look at session functions.