PHP Script to Validate URL

February 23, 2008 · Print This Article

I have been working to create a moderation tool for one of our project. In this project the members working for the project needs to submit links and snippets of the page. The moderators need to validate the links as many of the news pages are aggregated ones and the page expires after certain period of time.

I created a script which checks if the page is valid or returns a 404 error or any error

function validateURL2($url) {
    if(strlen($url)) {
        $file = @fopen ($url, "r");
        if ($file) {
        return true;
        }
        else return false;
        exit;
    }
    else return false;
}

This function actually checks for any error and returns true

Comments

Got something to say?