english/libraries/joomla/application/application.php
/**
	 * Redirect to another URL.
	 *
	 * Optionally enqueues a message in the system message queue (which will be displayed
	 * the next time a page is loaded) using the enqueueMessage method. If the headers have
	 * not been sent the redirect will be accomplished using a "301 Moved Permanently"
	 * code in the header pointing to the new location. If the headers have already been
	 * sent this will be accomplished using a JavaScript statement.
	 *
	 * @param   string   $url      The URL to redirect to. Can only be http/https URL
	 * @param   string   $msg      An optional message to display on redirect.
	 * @param   string   $msgType  An optional message type. Defaults to message.
	 * @param   boolean  $moved    True if the page is 301 Permanently Moved, otherwise 303 See Other is assumed.
	 *
	 * @return  void  Calls exit().
	 *
	 * @see     JApplication::enqueueMessage()
	 * @since   11.1
	 */
Redirect to another URL.
Optionally enqueues a message in the system message queue (which will be displayed
the next time a page is loaded) using the enqueueMessage method. If the headers have
not been sent the redirect will be accomplished using a "301 Moved Permanently"
code in the header pointing to the new location. If the headers have already been
sent this will be accomplished using a JavaScript statement.

@param   string   $url      The URL to redirect to. Can only be http/https URL
@param   string   $msg      An optional message to display on redirect.
@param   string   $msgType  An optional message type. Defaults to message.
@param   boolean  $moved    True if the page is 301 Permanently Moved, otherwise 303 See Other is assumed.

@return  void  Calls exit().


Redirect to another URL . Optionally enqueues a message in the system message queue ( which will be displayed the next time a page is loaded ) using the enqueueMessage method . If the headers have not been sent the redirect will be accomplished using a " 301 Moved Permanently " code in the header pointing to the new location . If the headers have already been sent this will be accomplished using a JavaScript statement . @param string $url The URL to redirect to . Can only be http / https URL @param string $msg An optional message to display on redirect . @param string $msgType An optional message type . Defaults to message . @param boolean $moved True if the page is 301 Permanently Moved otherwise 303 See Other is assumed . @return void Calls exit () .
public function redirect($url, $msg='', $msgType='message', $moved = false)
	{
		if (preg_match('#^index2?\.php#', $url)) {
			$url = JURI::base() . $url;
		}
		$url = preg_split("/[\r\n]/", $url);
		$url = $url[0];
		if (!preg_match('#^http#i', $url)) {
			$uri = JURI::getInstance();
			$prefix = $uri->toString(Array('scheme', 'user', 'pass', 'host', 'port'));
			if ($url[0] == '/') {
				$url = $prefix . $url;
			}
			else {
				$parts = explode('/', $uri->toString(Array('path')));
				array_pop($parts);
				$path = implode('/',$parts).'/';
				$url = $prefix . $path . $url;
			}
		}
		if (trim($msg)) {
			$this->enqueueMessage($msg, $msgType);
		}
		if (count($this->_messageQueue)) {
			$session = JFactory::getSession();
			$session->set('application.queue', $this->_messageQueue);
		}
		if (headers_sent()) {
			echo "<script>document.location.href='$url';</script>\n";
		}
		else {
			$document = JFactory::getDocument();
			jimport('joomla.environment.browser');
			$navigator = JBrowser::getInstance();
			if ($navigator->isBrowser('msie')) {
 				echo '<html><head><meta http-equiv="content-type" content="text/html; charset='.$document->getCharset().'" /><script>document.location.href=\''.$url.'\';</script></head><body></body></html>';
			}
			elseif (!$moved and $navigator->isBrowser('konqueror')) {
				echo '<html><head><meta http-equiv="refresh" content="0; url='. $url .'" /><meta http-equiv="content-type" content="text/html; charset='.$document->getCharset().'" /></head><body></body></html>';
			}
			else {
				header($moved ? 'HTTP/1.1 301 Moved Permanently' : 'HTTP/1.1 303 See other');
				header('Location: '.$url);
				header('Content-Type: text/html; charset='.$document->getCharset());
			}
		}
		$this->close();
	}
public function redirect ( $ url , $ msg = '' , $ msgType = 'message' , $ moved = false ) { if ( preg_match ( '#^index2?\.php#' , $ url ) ) { $ url = JURI :: base ( ) . $ url ; } $ url = preg_split ( " /[ \r \n ]/ " , $ url ) ; $ url = $ url [ 0 ] ; if ( ! preg_match ( '#^http#i' , $ url ) ) { $ uri = JURI :: getInstance ( ) ; $ prefix = $ uri -> toString ( Array ( 'scheme' , 'user' , 'pass' , 'host' , 'port' ) ) ; if ( $ url [ 0 ] == '/' ) { $ url = $ prefix . $ url ; } else { $ parts = explode ( '/' , $ uri -> toString ( Array ( 'path' ) ) ) ; array_pop ( $ parts ) ; $ path = implode ( '/' , $ parts ) . '/' ; $ url = $ prefix . $ path . $ url ; } } if ( trim ( $ msg ) ) { $ this -> enqueueMessage ( $ msg , $ msgType ) ; } if ( count ( $ this -> _messageQueue ) ) { $ session = JFactory :: getSession ( ) ; $ session -> set ( 'application.queue' , $ this -> _messageQueue ) ; } if ( headers_sent ( ) ) { echo " <script>document.location.href=' $ url ';</script> \n " ; } else { $ document = JFactory :: getDocument ( ) ; jimport ( 'joomla.environment.browser' ) ; $ navigator = JBrowser :: getInstance ( ) ; if ( $ navigator -> isBrowser ( 'msie' ) ) { echo '<html><head><meta http-equiv="content-type" content="text/html; charset=' . $ document -> getCharset ( ) . '" /><script>document.location.href=\'' . $ url . '\';</script></head><body></body></html>' ; } elseif ( ! $ moved and $ navigator -> isBrowser ( 'konqueror' ) ) { echo '<html><head><meta http-equiv="refresh" content="0; url=' . $ url . '" /><meta http-equiv="content-type" content="text/html; charset=' . $ document -> getCharset ( ) . '" /></head><body></body></html>' ; } else { header ( $ moved ? 'HTTP/1.1 301 Moved Permanently' : 'HTTP/1.1 303 See other' ) ; header ( 'Location: ' . $ url ) ; header ( 'Content-Type: text/html; charset=' . $ document -> getCharset ( ) ) ; } } $ this -> close ( ) ; }
Redirect to another URL.
Redirect to another URL .
// Check for relative internal links. // Strip out any line breaks. // If we don't start with a http we need to fix this before we proceed. // We could validly start with something else (e.g. ftp), though this would // be unlikely and isn't supported by this API. // We just need the prefix since we have a path relative to the root. // It's relative to where we are now, so lets add that. // If the message exists, enqueue it. // Persist messages if they exist. // If the headers have been sent, then we cannot send an additional location header // so we will output a javascript redirect statement. // MSIE type browser and/or server cause issues when url contains utf8 character,so use a javascript redirect method // WebKit browser (identified as konqueror by Joomla!) - Do not use 303, as it causes subresources reload (https://bugs.webkit.org/show_bug.cgi?id=38690) // All other browsers, use the more efficient HTTP header method