Find Broken Links In PHP - Online Code


This program produces a list of links in a page and their status. It tells you if the links are okay, if they've been moved somewhere else, or if they're bad. Run the program by passing it a URL to scan for links in GET query as It uses the cURL extension to retrieve web pages. First, it retrieves the URL specified on the GET query. Once a page has been retrieved, the program uses the XPath technique to get a list of links in the page. Then, after prepending a base URL to each link if necessary, the link is retrieved. Because we need just the headers of these responses, we use the HEAD method instead of GET by setting the CURLOPT_NOBODY option. Setting CURLOPT_HEADER tells curl_exec( ) to include the response headers in the string it returns. Based on the response code, the status of the link is printed, along with its new location if it's been moved.

Source Code


if (! isset($_GET['url'])) {
    die("No URL provided.\n");

$url = $_GET['url'];

// Load the page
list($page,$pageInfo) = load_with_curl($url);

if (! strlen($page)) {
    die("No page r
... (login or register to view full code)

To view full code, you must Login or Register, its FREE.

Hey, registering yourself just takes less than a minute and opens up a whole new GetGyan experience.


No comment yet. Be the first to post a comment.