Source for file jResponseRedirectUrl.class.php

Documentation is available at jResponseRedirectUrl.class.php

  1. <?php
  2. /**
  3. @package     jelix
  4. @subpackage  core_response
  5. @author      Laurent Jouanneau
  6. @contributor Loic Mathaud (fix bug)
  7. @copyright   2005-2010 Laurent Jouanneau, 2007 Loic Mathaud
  8. @link        http://www.jelix.org
  9. @licence     GNU Lesser General Public Licence see LICENCE file or http://www.gnu.org/licenses/lgpl.html
  10. */
  11.  
  12. /**
  13. * Response To redirect to an URL
  14. @package  jelix
  15. @subpackage core_response
  16. @see jResponse
  17. */
  18.  
  19. final class jResponseRedirectUrl extends jResponse {
  20.     protected $_type = 'redirectUrl';
  21.  
  22.     /**
  23.      * full url to redirect
  24.      * @var string 
  25.      */
  26.     public $url = '';
  27.     
  28.     /**
  29.      * true if it is a temporary redirection
  30.      * @var boolean 
  31.      */
  32.     public $temporary = true;
  33.  
  34.     /**
  35.      * set the url with the referer URL
  36.      * @return boolean true if there is a referer URL
  37.      * @since 1.0
  38.      */
  39.     public function toReferer($defaultUrl=''{
  40.         if(isset($_SERVER['HTTP_REFERER']&& $_SERVER['HTTP_REFERER'!= ''{
  41.             $this->url = $_SERVER['HTTP_REFERER'];
  42.             return true;
  43.         }
  44.         else {
  45.             $this->url = $defaultUrl;
  46.             return false;
  47.         }
  48.     }
  49.  
  50.     public function output(){
  51.         if ($this->url =='')
  52.             throw new jException('jelix~errors.repredirect.empty.url');
  53.         if($this->temporary)
  54.             $this->setHttpStatus(303'See Other');
  55.         else
  56.             $this->setHttpStatus(301'Moved Permanently');
  57.         $this->sendHttpHeaders();
  58.         header ('Location: '.$this->url);
  59.         return true;
  60.     }
  61. }

Documentation generated on Wed, 24 Sep 2014 22:01:35 +0200 by phpDocumentor 1.4.3