title: How to get the URL of a download link
body: <p>I am trying to parse a page which contains some links. These links, if followed, will redirect to some files to download.</p>
  
  <p>For example, <code>&lt;a href="http://example.com/file.php"&gt; Download &lt;/a&gt;</code> which redirects to <code>&lt;a href="http://example.com/1.pdf"</code>.</p>
  
  <p>I don't want to download the file, I just want to get the file link (int this case <code>http://example.com/1.pdf</code>).</p>
  
  <p>I am trying this:</p>
  
  <pre><code>curl_setopt($ch, CURLOPT_RETURNTRANSFER, FALSE);     // Return in string
  curl_setopt($ch, CURLOPT_URL, $url);
  curl_exec($ch);
  var_dump(curl_getinfo($ch));
  </code></pre>
  
  <p>But, it gives me the file contents.</p>
  
  <p>Does anyone have any idea how to this?</p>
  
  <p>==EDIT==<br>
  Thank you guys. I solved it like this:</p>
  
  <pre><code>curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
  curl_setopt($ch, CURLINFO_HEADER_OUT, TRUE);
  curl_setopt($ch, CURLOPT_URL, $url);
  curl_setopt($ch, CURLOPT_HEADER, TRUE);
  curl_setopt($ch, CURLOPT_NOBODY, TRUE);
  curl_exec($ch);
  $info = curl_getinfo($ch);
  </code></pre>
  
  <p>Now, <code>$info</code> contains the header and I can the link from it.</p>