Skip to content

Commit

Permalink
🔨 modify redirect function
Browse files Browse the repository at this point in the history
  • Loading branch information
otengkwame committed Nov 15, 2021
1 parent 413401e commit dcbdead
Showing 1 changed file with 20 additions and 18 deletions.
38 changes: 20 additions & 18 deletions framework/helpers/url_helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -514,8 +514,7 @@ function url_title($str, $separator = '-', $lowercase = FALSE)

// ------------------------------------------------------------------------

if ( ! function_exists('redirect'))
{
if ( ! function_exists('redirect')) {
/**
* Header Redirect
*
Expand All @@ -531,39 +530,42 @@ function url_title($str, $separator = '-', $lowercase = FALSE)
*/
function redirect($uri = '', $method = 'auto', $code = NULL)
{
if ( ! preg_match('#^(\w+:)?//#i', $uri))
{
$raw_uri = $uri;

if (strstr($uri, '.')) {
$uri = str_replace('.', '/', $uri);
}

if (strstr($uri, 'http') !== false || strstr($uri, 'https') !== false) {
$uri = $raw_uri;
}

if (!preg_match('#^(\w+:)?//#i', $uri)) {
$uri = site_url($uri);
}

// IIS environment likely? Use 'refresh' for better compatibility
if ($method === 'auto' && isset($_SERVER['SERVER_SOFTWARE']) && strpos($_SERVER['SERVER_SOFTWARE'], 'Microsoft-IIS') !== FALSE)
{
if ($method === 'auto' && isset($_SERVER['SERVER_SOFTWARE']) && strpos($_SERVER['SERVER_SOFTWARE'], 'Microsoft-IIS') !== FALSE) {
$method = 'refresh';
}
elseif ($method !== 'refresh' && (empty($code) OR ! is_numeric($code)))
{
if (isset($_SERVER['SERVER_PROTOCOL'], $_SERVER['REQUEST_METHOD']) && $_SERVER['SERVER_PROTOCOL'] === 'HTTP/1.1')
{
} elseif ($method !== 'refresh' && (empty($code) or !is_numeric($code))) {
if (isset($_SERVER['SERVER_PROTOCOL'], $_SERVER['REQUEST_METHOD']) && $_SERVER['SERVER_PROTOCOL'] === 'HTTP/1.1') {
$code = ($_SERVER['REQUEST_METHOD'] !== 'GET')
? 303 // reference: http://en.wikipedia.org/wiki/Post/Redirect/Get
: 307;
}
else
{
} else {
$code = 302;
}
}

switch ($method)
{
switch ($method) {
case 'refresh':
header('Refresh:0;url='.$uri);
header('Refresh:0;url=' . $uri);
break;
default:
header('Location: '.$uri, TRUE, $code);
header('Location: ' . $uri, TRUE, $code);
break;
}
exit;
}
}

0 comments on commit dcbdead

Please sign in to comment.