By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,491 Members | 1,181 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,491 IT Pros & Developers. It's quick & easy.

Urgent fopen question

P: n/a
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.
Jul 17 '05 #1
Share this Question
Share on Google+
3 Replies


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

Steve 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.

Jul 17 '05 #2

P: n/a
Ming wrote:
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
------------------------------------


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.

Jul 17 '05 #3

P: n/a
Ming wrote:
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
------------------------------------
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.
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?
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.
I'm try to use fopen to check if a link is broken. If anyone has a
workaround solution, it would be great, too.


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

--
Jock
Jul 17 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.