clankill3r Posted October 28, 2011 Share Posted October 28, 2011 I switched from hosting and now i got lot's of errors with functions i used before. And my hosting can't change shit due security... Anyway, they gave me this link and said this could do what i need: http://www.php.net/manual/en/function.curl-setopt.php#95027 <?php function curl_redirect_exec($ch, &$redirects, $curlopt_header = false) { curl_setopt($ch, CURLOPT_HEADER, true); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $data = curl_exec($ch); $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE); if ($http_code == 301 || $http_code == 302) { 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)) { curl_setopt($ch, CURLOPT_URL, $url); $redirects++; return curl_redirect_exec($ch, $redirects); } } if ($curlopt_header) return $data; else { list(,$body) = explode("\r\n\r\n", $data, 2); return $body; } } ?> I only have no idea of how to use it, i try this: $url = "http://www.google.nl"; $redirects = 0; $content = curl_redirect_exec($url, $redirects); I get this error atm: curl_setopt() expects parameter 1 to be resource, string given in Before i used: function getFileContents($url) { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_REFERER, CURLREFERER); $data = curl_exec($ch); curl_close($ch); return $data; } So must the $ch = curl_init(); be outside the function now? And if i must pass the curl_init(), then where do i pass the url? Could someone give me a example of how to use it? Quote Link to comment https://forums.phpfreaks.com/topic/249978-how-to-use-this-function/ Share on other sites More sharing options...
will35010 Posted October 31, 2011 Share Posted October 31, 2011 I have never used CURL inside of PHP, but it looks like it's having a problem with the variable $ch. Sorry that isn't much help. Quote Link to comment https://forums.phpfreaks.com/topic/249978-how-to-use-this-function/#findComment-1283704 Share on other sites More sharing options...
clankill3r Posted October 31, 2011 Author Share Posted October 31, 2011 every small parts help It was something like: $ch = curl_init('www.google.nl'); Not that hard after all, only new for me. Quote Link to comment https://forums.phpfreaks.com/topic/249978-how-to-use-this-function/#findComment-1283749 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.