How to get headers from fopen() call?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
PaulMM
Forum Newbie
Posts: 15
Joined: Wed Oct 01, 2008 8:21 am

How to get headers from fopen() call?

Post by PaulMM »

Hi everyone.
I'm writing a webpage downloader which downloads pages using CURL and fopen libraries. My script defines automatically which one is supported by customer's server and my script uses it automatically. I have written everything with CURL and now I want to develop a similar solution with fopen() because I want support both customers who have either fopen or curl. But I got a problem.

If I make an fopen call and a page redirects me to another location using http headers, the final url will be different than the one I requested. For example, if I request:
http://Host1.com/SomePage.html
and it redirects everyone using "302 Moved Temporarily" to
http://AnotherHost2.com/OtherPage.html
the final url obviously will be http://AnotherHost2.com/OtherPage.html but not http://Host1.com/SomePage.html.
So I will need to parse all the images at another location and moreover all pathes must be bound to another location!

Can someone tell me how can I access the http headers with fopen to define if I was redirected? If I could do it, I would simply take a look at "Location: " header and the problem would be solved. But how can I do it, how can I see http headers with fopen?

Thanks.

P.S. I do know well that CUrl allows watching http headers, but it is not a solution for me anymore. Because I need the same stuff for fopen solely.
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: How to get headers from fopen() call?

Post by Christopher »

(#10850)
PaulMM
Forum Newbie
Posts: 15
Joined: Wed Oct 01, 2008 8:21 am

Re: How to get headers from fopen() call?

Post by PaulMM »

How to do the same with php4.x? Is there any workaround?
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: How to get headers from fopen() call?

Post by Christopher »

You should always read the comments too:

http://www.php.net/manual/en/function.g ... .php#58295

And use Google and the PHP manual search:

http://us2.php.net/manual/en/reserved.v ... header.php
(#10850)
PaulMM
Forum Newbie
Posts: 15
Joined: Wed Oct 01, 2008 8:21 am

Re: How to get headers from fopen() call?

Post by PaulMM »

thanks
Post Reply