开发者

Grab the page which is redirecting

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 anoth开发者_StackOverflower page which shows the content of the .pdf within an Iframe.

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

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

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.

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.


If you are doing the HTTP stuff manually, check for 30x statuscodes and the Location header.

However, you could simply use CURL and set CURLOPT_FOLLOWLOCATION.


Yes, just like ThiefMaster said, you could look for the Location header. Have a look here, maybe this can be a help to you: http://codesnippets.joyent.com/posts/show/1214 This function retrieves file size of a remote file, why don't you try to change it slightly so that it gets the final URL?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜