Grab the page which is redirecting
<p>I am trying to grab a file .pdf from a server. There is a hyperlink at the page, by clicking that link it goes to a page, it checks for some privileges, then it redirects to another page which shows the content of the .pdf within an Iframe.</p>

<p>lets say beginning url is <a href="http://site.com/docs/1.pdf" rel="nofollow">http://site.com/docs/1.pdf</a>
on click it goes to another page, then another one and it comes whth the last page 
<a href="http://site.com/viewer/pdfs/1.pdf" rel="nofollow">http://site.com/viewer/pdfs/1.pdf</a>
the last page shows the pdf content within an Iframe.</p>

<p>I realized that the software IDM (Internet download manager) can follow the redirections and download the file by clicking the first link. </p>

<p>I was wondering if there is an algorithm or library or class or hint that I can figure out how to do that in PHP scripting. </p>

<p>by the way, once I wrote a code to read the header of the page and I could redirect to the second page, but I want to know if there is a general algorithm for this or not.</p>
