Česky
Kamil Dudka

Web components

File detail

Name:DownloadRedirect.class.php [Download]
Location: src > lib
Size:1.1 KB
Last modification:2022-09-09 13:06

Source code

<?php
/**
 * @file Redirect.class.php
 * Definition of Redirect class.
 * @author Kamil Dudka <xdudka00@gmail.com>
 */
 
// Dependent on SmartyFactory class
ClassFactory::importClass('SmartyFactory');
 
/**
 * Class sends redirect request to client.
 * This class is not instantiable for now.
 */
class Redirect {
  /**
   * Send redirect request to client
   * @param redirTo URL to redirect to.
   * @param lang (voluntary) Page language. It has no effect if HTTP redirection works.
   * @remarks
   * - Redirect using HTTP header (best case)
   * - Redirect using Javascript (alternative case)
   * - Redirect by user clicking on link (emergency case)
   */
  public static function redirect($redirTo, $lang=null) {
    // Attempt to redirect automatically via HTTP header
    Header('Location: '.$redirTo);
 
    // Emergency redirect by JavaScript
    // (or by user, if there is no JavaScript)
    $smarty = SmartyFactory::createSmarty();
    $smarty->assign('redirTo', $redirTo);
    if (isset($lang))
      $smarty->assign('lang', $lang);
    $smarty->display('Redirect.tpl');
    exit();
  }
  // Avoid class instantiation
  private function __construct() { }
};
?>