To go to the previous page, the address needs to be passed through the accesscheck querystring variable
What is the address in the address bar when you get to the login page? Does it contain the accesscheck querystring variable?
You can see an example of this by adding Page Access restriction to a page, set it to go to the login page if not logged in, then try to access it.
To debug the cart page, add the following code just after the body tag:
<pre><?php var_dump($_SESSION); ?></pre>
this will write the session contents to the cart page, post back the session contents.