cyfer65 Posted October 5, 2009 Share Posted October 5, 2009 I made a PHP curl page that works ok, but with some URLs it gives me an "Object Moved, This document may be found here" with a link to go to the site the original URL is forwarding to..so my question is how can i make the php page get that new URL & then curl it..?? Link to comment Share on other sites More sharing options...
justsomeguy Posted October 5, 2009 Share Posted October 5, 2009 You would have to check the response and go to the new URL, most of the time a 3xx response indicates that the item was moved or is being redirected. It will usually use a location header to indicate the new URL. Link to comment Share on other sites More sharing options...
cyfer65 Posted October 11, 2009 Author Share Posted October 11, 2009 how exactly could i do that..??Is there a way to first check the URL to see if it redirects to another site & if it does then use that URL for the CURL job..??this is my php code so far.. what can I add or change to make it check the URL first before it does the CURL process..?? <?php$Link = $_SERVER['QUERY_STRING'];$uri = parse_url($Link);$base = "http://".$uri[host].""; echo geturl($Link, $base); function geturl($url, $referer) { $headers[] = 'Accept: image/png, image/gif, image/x-bitmap, image/jpeg, image/pjpeg'; $headers[] = 'Connection: Keep-Alive'; $headers[] = 'Content-type: application/x-www-form-urlencoded;charset=UTF-8'; $UserAgent = 'Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0)'; $process = curl_init($url); curl_setopt($process, CURLOPT_HTTPHEADER, $headers); curl_setopt($process, CURLOPT_HEADER, 0); curl_setopt($process, CURLOPT_USERAGENT, $UserAgent); curl_setopt($process, CURLOPT_REFERER, $referer); curl_setopt($process, CURLOPT_TIMEOUT, 60); curl_setopt($process, CURLOPT_RETURNTRANSFER, 1); curl_setopt($process, CURLOPT_FOLLOWLOCATION, 1); $return = curl_exec($process); curl_close($process); return $return; } ?> Link to comment Share on other sites More sharing options...
justsomeguy Posted October 11, 2009 Share Posted October 11, 2009 I haven't used CURL for much, so I don't know what you need to do. Check the CURL documentation, you would probably do something with either the return value of the curl_exec function or $process. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.