Created
June 16, 2012 19:51
-
-
Save narfbg/2942361 to your computer and use it in GitHub Desktop.
CI redirect() HTTP code 303 auto-detection
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/system/helpers/url_helper.php b/system/helpers/url_helper.php | |
index 40ce807..add7f72 100644 | |
--- a/system/helpers/url_helper.php | |
+++ b/system/helpers/url_helper.php | |
@@ -526,7 +526,7 @@ if ( ! function_exists('redirect')) | |
* @param int | |
* @return string | |
*/ | |
- function redirect($uri = '', $method = 'auto', $http_response_code = 302) | |
+ function redirect($uri = '', $method = 'auto', $code = NULL) | |
{ | |
if ( ! preg_match('#^https?://#i', $uri)) | |
{ | |
@@ -538,14 +538,21 @@ if ( ! function_exists('redirect')) | |
{ | |
$method = 'refresh'; | |
} | |
+ elseif ($method !== 'refresh' && (empty($code) OR ! is_numeric($code))) | |
+ { | |
+ $code = (isset($_SERVER['REQUEST_METHOD'], $_SERVER['SERVER_PROTOCOL']) | |
+ && $_SERVER['REQUEST_METHOD'] === 'POST' | |
+ && $_SERVER['SERVER_PROTOCOL'] === 'HTTP/1.1') | |
+ ? 303 : 302; | |
+ } | |
- switch($method) | |
+ switch ($method) | |
{ | |
case 'refresh': | |
header('Refresh:0;url='.$uri); | |
break; | |
default: | |
- header('Location: '.$uri, TRUE, $http_response_code); | |
+ header('Location: '.$uri, TRUE, $code); | |
break; | |
} | |
exit; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment