Exemplo n.º 1
0
 /**
  * \PHPYAM\core\Router initialization
  */
 private function initRouter()
 {
     // We set a session name based on the "baseurl"
     // to not mix the session data of different web applications
     // on a same webserver domain.
     session_name('SESS' . md5($_SERVER['HTTP_HOST'] . URL));
     // Must be run asap by the router!
     if (session_id() === '') {
         session_start();
     }
     // We set the language used for the PHPYAM messages.
     // Can be overridden later again, for example
     // in the object constructor of $this->authentication.
     putenv('LC_ALL=' . CLIENT_LANGUAGE);
     setlocale(LC_ALL, CLIENT_LANGUAGE);
     bindtextdomain('PHPYAM', __DIR__ . '/../locales');
     bind_textdomain_codeset('PHPYAM', CLIENT_CHARSET);
     // Useful for Ajax requests (JQuery).
     header('Content-Type: text/html; charset=' . CLIENT_CHARSET);
     // The Ajax directive 'contentType: "application/x-www-form-urlencoded;charset=" . CLIENT_CHARSET'
     // is ignored by mostly every web browser (and should therefore not be used).
     // They will *always* send Ajax requests encoded with the UTF-8 charset.
     // We must therefore re-encode the received query data ($_POST, $_GET, ...) using the server&client charset:
     if (self::isAjaxCall() && is_array($GLOBALS['_' . $_SERVER['REQUEST_METHOD']])) {
         array_walk_recursive($GLOBALS['_' . $_SERVER['REQUEST_METHOD']], '\\PHPYAM\\libs\\StringUtils::stringEncode', array('from' => 'UTF-8', 'to' => CLIENT_CHARSET));
     }
     // Prevent accidental submitting by refresh or back-button.
     // Use after session_start() and before any output to the browser (it uses header redirection).
     IntelliForm::antiRepost($_SERVER['REQUEST_URI']);
     // Clear expired form data.
     IntelliForm::purge();
     // Create array with URL parts in $url.
     $this->splitUrl();
     $this->loadResource(SYS_APP . '/security', SECURITY_POLICY);
     $authenticationClassName = SECURITY_POLICY;
     $this->authentication = new $authenticationClassName();
     // We check that the header() statements have been taken into account,
     // which is only possible if the HTTP headers have not been sent yet.
     Assert::isFalse(headers_sent(), StringUtils::gettext('HTTP headers have already been sent.'));
     ob_start();
 }