How to detect page redirect with PHP?
- by blabus
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!