PHP Script to Validate URL

by Kishore on February 23, 2008

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

Possibly Interesting Posts

Sorry I could to find you one, will try next time..

{ 2 comments… read them below or add one }

jeroen September 4, 2008 at 4:08 am

Nice post. I\’ll return.<

Reply

siri June 14, 2009 at 5:49 pm

This is really interesting…especially for bloggers who would like to keep their status updated.

Reply

Leave a Comment

Previous post:

Next post: