How to redirect to another url in block or template

In Block class:

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; 

你可能感兴趣的:(PHP)