How to check if a webpage exists. jQuery and/or PHP

后端 未结 4 619
长发绾君心
长发绾君心 2021-01-05 07:55

I want to be able to validate a form to check if a website/webpage exists. If it returns a 404 error then that definitely shouldn\'t validate. If there is a redirect...I\'m

4条回答
  •  日久生厌
    2021-01-05 08:48

    I've just written a simpler version using PHP:

    function url_check($url) {
    
    $x = @fopen($url,"r");
    
    if ($x) {
    
             $reply = 1;
    
             fclose($x);
    
    } else {
    
                $reply = 0;
    
    }
    
    return $reply;
    
    }
    

    Obviously $url is the test URL, returns true (1) or false (0) depending on URL existence.

提交回复
热议问题