MyBB Community Forums

Full Version: Checking for broken links?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi guys,

I'm trying to create a plugin that will check if a URL exists in a post or not. If it does exist, it will not do anythig. If it doesn't exist, I need to perform a query on it.
Just wondering if anyone knew a good script that checks the URL's on a page and checks if there valid. I've seen a few but most appear to say their valid, even if they don't.

Thanks Smile
Best way to do it IMO is to try visiting the links via CURL to see if they load. Problem is that will be pretty slow unless you do it via a task or something.
Cheers Euan, I found this one:

       //returns true, if domain is availible, false if not
       function isDomainAvailible($domain)
               //check, if a valid url is provided
               if(!filter_var($domain, FILTER_VALIDATE_URL))
                       return false;

               //initialize curl
               $curlInit = curl_init($domain);

               //get answer
               $response = curl_exec($curlInit);


               if ($response) return true;

               return false;

              if (isDomainAvailible(''))
               echo "Up and running!";
               echo "Woops, nothing found there.";

But it is always displaying "Up and running!", even f it doesn't exist (like in the example above)

Cheers Smile