Magento Customer redirection

Magento Customer redirection we can redirect customer to previous page after login instead of my account dashboard

we just have to follow below steps and code

Admin – >System -> Configuration -> CUSTOMERS -> Customer Configuration -> Login Options -> Redirect Customers to Account Dashboard after Loggin in = No

setup login required to view page

add below code on page start and user will be restricted with login

<?php 
if(!Mage::helper('customer')->isLoggedIn()) {
  Mage::getSingleton('customer/session')
            ->setBeforeAuthUrl(Mage::helper('core/url')->getCurrentUrl()); 
  $this->_redirect('customer/account/login');
}
?>

redirect customer to its previous page after adding item to cart

Admin – >System -> Configuration -> Sales -> Checkout -> After Adding a Product Redirect to Shopping Cart = No