In Block class:
In template(phtml):
public function _toHtml(){
Mage::getSingleton('customer/session')->setBeforeAuthUrl($this->getRequest()->getRequestUri());
if (!Mage::getSingleton('customer/session')->isLoggedIn()){
header("Status: 301");
header('Location: '.$this->getUrl('customer/account/login')) ; // send to the login page
exit;
}
}
In template(phtml):
Mage::getSingleton('customer/session')->setBeforeAuthUrl($this->getRequest()->getRequestUri());
if (!Mage::getSingleton('customer/session')->isLoggedIn()){
header("Status: 301");
header('Location: '.$this->getUrl('customer/account/login')) ; // send to the login page
exit;