Is there any way I can know from which page I came from?
This sounds similar to a payment processor flow (especially the "button" style processors). In those, you typically pass a "return URL" to the remote site, and they would in turn direct your visitor back to the specified URL.

If the return URL needs to be a separate callback (eg an IPN URL), then you might add additional parameters (&amp;return=civicrm%2Fevent%3Fid%3D1%26reset%3D1) to the IPN URL, and the IPN can in turn decode that (civicrm/event?id=1&amp;reset=1) and perform a final redirect to land the user on the page they originated from.