Connecting Tech Pros Worldwide Forums | Help | Site Map

Urgent fopen question

Ming
Guest
 
Posts: n/a
#1: Jul 17 '05
When I use fopen on the URL:
fopen("http://home.pchome.com.tw/world/qoo4ko/110.jpg";, "r")
I would get the following error message:

-----------Error Message------------
Warning: fopen(): Circular redirect, aborting.
Warning: fopen(http://home.pchome.com.tw/world/qoo4ko/110.jpg): failed
to open stream: Permission denied
------------------------------------

But when I use HTML (<img src="<?=$URL?>" alt="">), to display it, it
does display on the screen.

How come fopen cannot open certain URLs while <img> can display them.
Does anyone have any idea why this happens?

I'm try to use fopen to check if a link is broken. If anyone has a
workaround solution, it would be great, too.

Thanks very much.

Steve
Guest
 
Posts: n/a
#2: Jul 17 '05

re: Urgent fopen question


Ming wrote:[color=blue]
> When I use fopen on the URL:
> fopen("http://home.pchome.com.tw/world/qoo4ko/110.jpg";, "r")[/color]
Does it work any better when you put the semicolon at the end instead of
the middle of the line?

Steve[color=blue]
> I would get the following error message:
>
> -----------Error Message------------
> Warning: fopen(): Circular redirect, aborting.
> Warning: fopen(http://home.pchome.com.tw/world/qoo4ko/110.jpg): failed
> to open stream: Permission denied
> ------------------------------------
>
> But when I use HTML (<img src="<?=$URL?>" alt="">), to display it, it
> does display on the screen.
>
> How come fopen cannot open certain URLs while <img> can display them.
> Does anyone have any idea why this happens?
>
> I'm try to use fopen to check if a link is broken. If anyone has a
> workaround solution, it would be great, too.
>
> Thanks very much.[/color]
Colin McKinnon
Guest
 
Posts: n/a
#3: Jul 17 '05

re: Urgent fopen question


Ming wrote:
[color=blue]
> When I use fopen on the URL:
> fopen("http://home.pchome.com.tw/world/qoo4ko/110.jpg";, "r")
> I would get the following error message:
>
> -----------Error Message------------
> Warning: fopen(): Circular redirect, aborting.
> Warning: fopen(http://home.pchome.com.tw/world/qoo4ko/110.jpg): failed
> to open stream: Permission denied
> ------------------------------------
>[/color]

Never seen this with fopen(...); but I have seen it in Konqueror (a web
browser) when the page issues a redirect to it's own URL (other browsers
happily follow the redirection).

Try getting the headers from http://home.pchome.com.tw/world/qoo4ko/110.jpg
and see if it returns a 200 or something else.

HTH

C.

John Dunlop
Guest
 
Posts: n/a
#4: Jul 17 '05

re: Urgent fopen question


Ming wrote:
[color=blue]
> When I use fopen on the URL:
> fopen("http://home.pchome.com.tw/world/qoo4ko/110.jpg";, "r")
> I would get the following error message:
>
> -----------Error Message------------
> Warning: fopen(): Circular redirect, aborting.
> Warning: fopen(http://home.pchome.com.tw/world/qoo4ko/110.jpg): failed
> to open stream: Permission denied
> ------------------------------------[/color]

That's right. It's a 'circular redirect', or an infinite
loop. HTTP/1.0, the previous HTTP spec, said that 'a user
agent should never automatically redirect a request more
than 5 times, since such redirections usually indicate an
infinite loop'; HTTP/1.1 says that 'a client SHOULD detect
infinite redirection loops, since such loops generate
network traffic for each redirection'. Fopen apparently
follows this advice.
[color=blue]
> But when I use HTML (<img src="<?=$URL?>" alt="">), to display it, it
> does display on the screen.
>
> How come fopen cannot open certain URLs while <img> can display them.
> Does anyone have any idea why this happens?[/color]

Smells awfully like browser sniffing to me. The response
differs depending on the request's User-Agent header. If
User-Agent contains 'Mozilla', for instance, the status code
is 200, OK; with no User-Agent header, it's 302 -- a
temporary redirection.
[color=blue]
> I'm try to use fopen to check if a link is broken. If anyone has a
> workaround solution, it would be great, too.[/color]

Use fsockopen. Send a HEAD request and read the status code
from the first line of the response.

--
Jock
Closed Thread