How to detect page redirect with PHP?
Posted
by blabus
on Stack Overflow
See other posts from Stack Overflow
or by blabus
Published on 2010-05-20T17:13:46Z
Indexed on
2010/05/20
17:20 UTC
Read the original article
Hit count: 242
I'm trying to detect whether an image exists on a remote server. However, I've tried several methods and can't get any of them to work.
Right now I'm trying to use this:
if (!CheckImageExists("http://img2.netcarshow.com/ABT-Audi_R8_2008_1024x768_wallpaper_01.jpg")) { print_r("DOES NOT EXIST"); } else { print_r("DOES EXIST"); }; function CheckImageExists($imgUrl) { if (fopen($imgUrl, "r")) { return true; } else { return false; }; };
But it returns 'true' whether the image actually exists or not (the above image should, but change it to gibberish and it still will return 'true'). I have a feeling it could be because if the URL does not exist, it redirects to the homepage of the site. But I don't know how to detect that.
Thanks for any help!
© Stack Overflow or respective owner