The Goto Previous URL setting relies on a Querystring variable.
When you visit a protected page, you will be redirected to the login page with the accesscheck querystring variable set to the page you where redirected from.
you can create a link to the login page that that has the accesscheck variable set so that you will be redirected:
<a href="login.php?accesscheck=<?php echo (urlencode($_SERVER["PHP_SELF"].(isset($_SERVER["QUERY_STRING"])?"?".htmlentities($_SERVER["QUERY_STRING"]):"")));?>">Log In</a>