Gating/Redirecting anonymous user back to an origin page after logging in/registration
You can have destination parameter in url. Something like below.

drupal_goto('custom/user/login', array('query' =&gt; array('destination' =&gt; current_path())));