How can I check if a URL exists via PHP?

前端 未结 22 1644
天涯浪人
天涯浪人 2020-11-22 04:13

How do I check if a URL exists (not 404) in PHP?

22条回答
  •  南方客
    南方客 (楼主)
    2020-11-22 05:00

    kind of an old thread, but.. i do this:

    $file = 'http://www.google.com';
    $file_headers = @get_headers($file);
    if ($file_headers) {
        $exists = true;
    } else {
        $exists = false;
    }
    

提交回复
热议问题