title: PHP Curl following redirects
body: <p>I'm trying to be a bit sneeky and as part of a learning process try and improve my page scraping skills.</p>
  
  <p>One thing i've come across that I have yet to be able to solve is that certain sites will use an internal link which then redirects to an external link.</p>
  
  <p>What I want to do is modify some curl code to follow the redirects until they stop and then obtain the final resting place URL.</p>
  
  <p>Anyone recommend some code for me?</p>
  
  <p>I have this at the moment, but it's not following the redirects properly at the moment.</p>
  
  <pre><code>        $opts = array(CURLOPT_URL =&gt; $url,
                        CURLOPT_RETURNTRANSFER =&gt; true,
                        CURLOPT_HEADER =&gt; true,
                        CURLOPT_FOLLOWLOCATION =&gt; true);      
  
          $curl = curl_init(); 
          curl_setopt_array($curl, $opts);  
          $str = curl_exec($curl);  
          curl_close($curl);  
  </code></pre>