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: 240

Filed under:
|
|
|
|

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

Related posts about php

Related posts about detect

  • Ruby Detect method

    as seen on Stack Overflow - Search for 'Stack Overflow'
    Select makes sense. But can someone explain .detect to me? I don't understand these data. >> [1,2,3,4,5,6,7].detect { |x| x.between?(3,4) } => 3 >> [1,2,3,4,5,6,7].detect { |x| x.between?(3,6) } => 3 >> [1,2,3,4,5,6,7].detect { |x| x.between?(3,7) } => 3 >> [1,2,3… >>> More

  • How to connect Nexus 7 with Ubuntu

    as seen on Ask Ubuntu - Search for 'Ask Ubuntu'
    I want to move some files from my PC to Nexus 7. The tablet is connected to my PC's USB port and it is successfully charging. Unfortunately, the PC is not detecting the devices - what I expected is to be shown the Nexus 7 tablet as external devices (like my USB flash memory). As the tablet is connected… >>> More

  • Second monitor not detected

    as seen on Ask Ubuntu - Search for 'Ask Ubuntu'
    Note: I've seen this question quite a lot, but in all the cases I could find with answers, the answer was either "I don't know" or "use nvidia-settings (which is irrelevant to me)." I'm using Intel Sandybridge Desktop graphics, with a P8H61-M LE motherboard. How do I get Ubuntu to detect my second… >>> More

  • USB Flash Drive not Detected on 12.10 x64

    as seen on Ask Ubuntu - Search for 'Ask Ubuntu'
    My Mediatek usb flash drive is not get detected. The o/p of lsusb falguni@falguni-M61PME-S2P:~$ lsusb Bus 002 Device 002: ID 0e8d:0003 MediaTek Inc. Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub Bus 002 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub and the o/p of usb-devices falguni@falguni-M61PME-S2P:~$… >>> More

  • mac os x - detect file system read

    as seen on Super User - Search for 'Super User'
    I want to know what files a specific application is trying to access on my disc. I know that you can use fs_usage, but this outputs events from all applications. I know that you can target a single application, but only one that is already running. I want to detect all readfile-events an application… >>> More