From bb16186fabdbd4b49ad4ff13552d97a0462e298a Mon Sep 17 00:00:00 2001 From: Olaf Conradi Date: Wed, 26 Dec 2012 04:03:12 +0100 Subject: Add permanent redirect (308) http code Add 308 http code next to 301, 302, 303 and 307. Close curl session before returning on redirect. Let post_url redirect using post_url, not fetch_url (which is actually 308 behavior). --- include/network.php | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'include/network.php') diff --git a/include/network.php b/include/network.php index 0f1420d61..5571285b4 100644 --- a/include/network.php +++ b/include/network.php @@ -72,7 +72,7 @@ function fetch_url($url,$binary = false, &$redirects = 0, $timeout = 0, $accept_ $base = substr($base,strlen($chunk)); } - if($http_code == 301 || $http_code == 302 || $http_code == 303 || $http_code == 307) { + if($http_code == 301 || $http_code == 302 || $http_code == 303 || $http_code == 307 || $http_code == 308) { $matches = array(); preg_match('/(Location:|URI:)(.*?)\n/', $header, $matches); $newurl = trim(array_pop($matches)); @@ -81,6 +81,7 @@ function fetch_url($url,$binary = false, &$redirects = 0, $timeout = 0, $accept_ $url_parsed = @parse_url($newurl); if (isset($url_parsed)) { $redirects++; + @curl_close($ch); return fetch_url($newurl,$binary,$redirects,$timeout); } } @@ -161,7 +162,7 @@ function post_url($url,$params, $headers = null, &$redirects = 0, $timeout = 0) $base = substr($base,strlen($chunk)); } - if($http_code == 301 || $http_code == 302 || $http_code == 303) { + if($http_code == 301 || $http_code == 302 || $http_code == 303 || $http_code == 307 || $http_code == 308) { $matches = array(); preg_match('/(Location:|URI:)(.*?)\n/', $header, $matches); $newurl = trim(array_pop($matches)); @@ -170,7 +171,8 @@ function post_url($url,$params, $headers = null, &$redirects = 0, $timeout = 0) $url_parsed = @parse_url($newurl); if (isset($url_parsed)) { $redirects++; - return fetch_url($newurl,false,$redirects,$timeout); + @curl_close($ch); + return post_url($newurl,false,$redirects,$timeout); } } $a->set_curl_code($http_code); @@ -247,7 +249,7 @@ function z_fetch_url($url,$binary = false, &$redirects = 0, $timeout = 0, $accep $base = substr($base,strlen($chunk)); } - if($http_code == 301 || $http_code == 302 || $http_code == 303 || $http_code == 307) { + if($http_code == 301 || $http_code == 302 || $http_code == 303 || $http_code == 307 || $http_code == 308) { $matches = array(); preg_match('/(Location:|URI:)(.*?)\n/', $header, $matches); $newurl = trim(array_pop($matches)); @@ -339,7 +341,7 @@ function z_post_url($url,$params, $headers = null, &$redirects = 0, $timeout = 0 $base = substr($base,strlen($chunk)); } - if($http_code == 301 || $http_code == 302 || $http_code == 303) { + if($http_code == 301 || $http_code == 302 || $http_code == 303 || $http_code == 307 || $http_code == 308) { $matches = array(); preg_match('/(Location:|URI:)(.*?)\n/', $header, $matches); $newurl = trim(array_pop($matches)); -- cgit v1.2.3