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