note 95943 added to function.curl-setopt

From: Date: Fri, 29 Jan 2010 18:41:17 +0000
Subject: note 95943 added to function.curl-setopt
Groups: php.notes 
Request: Send a blank email to php-notes+get-165499@lists.php.net to get a copy of this message
I would like to improve redirect function. Actually it has to catch also a redirection by meta refresh tag. function redirect_exec($ch, $curlopt_header = false) { curl_setopt($ch, CURLOPT_HEADER, true); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $data = curl_exec($ch); $info = curl_getinfo($ch); $http_code = $info['http_code']; if ($http_code == 301 || $http_code == 302 || $http_code == 303) { list($header) = explode("\r\n\r\n", $data, 2); $matches = array(); preg_match('/(Location:|URI:)(.*?)\n/', $header, $matches); $url = trim(array_pop($matches)); $url_parsed = parse_url($url); if (isset($url_parsed['host'])) { curl_setopt($ch, CURLOPT_URL, $url); return redirect_exec($ch); } } elseif($http_code == 200){ $matches = array(); preg_match('/(<meta http-equiv=)(.*?)(refresh)(.*?)(url=)(.*?)[\'|"]\s*>/', strtolower($data), $matches); $url = trim(array_pop($matches)); $url_parsed = parse_url($url); if (isset($url_parsed['host'])) { curl_setopt($ch, CURLOPT_URL, $url); return redirect_exec($ch); } } return $info['url']; } ---- Server IP: 92.48.119.85 Probable Submitter: 70.28.47.108 ---- Manual Page -- http://www.php.net/manual/en/function.curl-setopt.php Edit -- https://master.php.net/note/edit/95943 Del: integrated -- https://master.php.net/note/delete/95943/integrated Del: useless -- https://master.php.net/note/delete/95943/useless Del: bad code -- https://master.php.net/note/delete/95943/bad+code Del: spam -- https://master.php.net/note/delete/95943/spam Del: non-english -- https://master.php.net/note/delete/95943/non-english Del: in docs -- https://master.php.net/note/delete/95943/in+docs Del: other reasons-- https://master.php.net/note/delete/95943 Reject -- https://master.php.net/note/reject/95943 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#165499) next »