>
Problem with CURLOPT_FOLLOWLOCATION
Welcome, Guest

by Sumit on Friday, 21 November 2008
Problem with CURLOPT_FOLLOWLOCATION


Solution :: Instead of calling this :: curl_setopt($ch, CURLOPT_FOLLOWLOCATION,1); call this Method( Definition of this function is at the end) $this->curl_redir_exec($ch); If safe_mode was activated and/or an open_basedir restriction was set,the cURL option CURLOPT_FOLLOWLOCATION can't be switched to true. You will be informed about this with a warning from PHP With this Statement :: curl_setopt($ch, CURLOPT_FOLLOWLOCATION,1); we are saying that follow all the locations for logging in to the account wherever the third party server sends you and if we have safe_mode activated and/or an open_basedir restriction was set,so we will be unable to login in Gmail account and get the addresses from there So what we have to do in this scenario,we just have tpo call a function which will call the locations recursively. The Method is like the below one function curl_redir_exec($ch,$debug="") { static $curl_loops = 0; static $curl_max_loops = 20; if ($curl_loops++ >= $curl_max_loops) { $curl_loops = 0; return false; } curl_setopt($ch, CURLOPT_HEADER, true); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $data = curl_exec($ch); $debbbb = $data; list($header, $data) = explode("nn", $data, 2); $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE); if ($http_code == 301 || $http_code == 302) { $matches = array(); preg_match('/Location:(.*?)n/', $header, $matches); $url = @parse_url(trim(array_pop($matches))); //print_r($url); if (!$url) { $curl_loops = 0; return $data; } $last_url = parse_url(curl_getinfo($ch, CURLINFO_EFFECTIVE_URL)); $new_url = $url['scheme'] . '://' . $url['host'] . $url['path'] . ($url['query']?'?'.$url['query']:''); curl_setopt($ch, CURLOPT_URL, $new_url); return $this->curl_redir_exec($ch); } else { $curl_loops=0; return $debbbb; } } This function will call itself again and again until the last location is reached



Blogger Image
My Blog Title

Product Engineering, software engineering company, Product Development, Product Migration, Product Re-engineering, Product Maintenance, Product Testing Commercial Application Development, Business Software development, commercial software for startups, Application Support and Maintenance, software testing Product Maintenance, Outsource product maintenance, product support and maintenance Product Migration, Product Re-engineering, product re-engineering services Product Research, Product Engineering, UI Prototyping Services Software Testing Services, Quality Assurance services, professional software testers, Load Testing, Functional Testing, Cross Platform, Browser Testing, Test Automation, Testing Tools, software quality analysis Functional Testing Services, software quality analysis, Software Testing Services, Application Testing Services, Functional Testing Types Automated Testing, Automated Testing Services, automation testing, test script development, Automation Test Tools, outsource automation testing Load Testing, Performance Testing Services, Load Testing Tools Offshore Software Development, Outsource software services, offshore outsourcing services, offshore software development services, IT outsourcing services, software quality assurance services, Offshore IT services, Custom Application Development Services, Offshore Product Engineering Benefits of IT Outsourcing, Offshore Software Development companies, offshore software development firms Outsource planning, IT outsourcing, IT development services, offshore IT companies, offshore software development Offshore Software Development, Outsource software services, offshore outsourcing services, offshore software development services, IT outsourcing services, software quality assurance services, Offshore IT services, Custom Application Development Services, Offshore Product Engineering Offshore Software Development, Outsource software services, offshore outsourcing services, offshore software development services, IT outsourcing services, software quality assurance services, Offshore IT services, Custom Application Development Services, Offshore Product Engineering