/** * Test on \Includes\Utils\Converter::removeCRLF * * @return void * @see ____func_see____ * @since 1.0.3 */ public function testRemoveCRLF() { $url = $etalonURL = 'admin.php?target=main'; $this->assertEquals($etalonURL, \Includes\Utils\Converter::removeCRLF($url), 'removeCRLF() test #1 failed'); $url = ' admin.php?target=main '; $this->assertEquals($etalonURL, \Includes\Utils\Converter::removeCRLF($url), 'removeCRLF() test #2 failed'); $url = <<<OUT admin.php?target=main OUT; $this->assertEquals($etalonURL, \Includes\Utils\Converter::removeCRLF($url), 'removeCRLF() test #3 failed'); $this->assertEquals('', \Includes\Utils\Converter::removeCRLF(null), 'removeCRLF() test #4 failed'); $this->assertEquals('0', \Includes\Utils\Converter::removeCRLF(0), 'removeCRLF() test #5 failed'); $this->assertEquals('5', \Includes\Utils\Converter::removeCRLF(5), 'removeCRLF() test #6 failed'); }
/** * Redirect * * @param string $location URL * @param int $code operation code * * @return void */ public static function redirect($location, $code = 302) { $location = \Includes\Utils\Converter::removeCRLF($location); if ('cli' !== PHP_SAPI) { if (headers_sent()) { $message = '<a href="' . $location . '">Click here to redirect</a>'; $jsOutput = 'self.location = \'' . $location . '\';'; static::flush($message, true, $jsOutput); } else { header('Location: ' . $location, true, $code); } } exit(0); }
/** * setHeaderLocation * * @param string $location URL * @param integer $code Operation code OPTIONAL * * @return void */ protected static function setHeaderLocation($location, $code = 302) { $location = \Includes\Utils\Converter::removeCRLF($location); if (headers_sent()) { // HTML meta tags-based redirect echo '<script type="text/javascript">' . "\n" . '<!--' . "\n" . 'self.location=\'' . $location . '\';' . "\n" . '-->' . "\n" . '</script>' . "\n" . '<noscript><a href="' . $location . '">Click here to redirect</a></noscript><br /><br />'; } elseif (\XLite\Core\Request::getInstance()->isAJAX() && 200 == $code) { // AJAX-based redirct header('AJAX-Location: ' . $location, true, $code); } else { // HTTP-based redirect header('Location: ' . $location, true, $code); } }