Jump to content

PHP link checker


charanv

Recommended Posts

This works for me (PHP5):

 

<?php

function getHeadersCurl($url) { 
    $ch = curl_init(); 
    curl_setopt($ch, CURLOPT_URL,            $url); 
    curl_setopt($ch, CURLOPT_HEADER,         true); 
    curl_setopt($ch, CURLOPT_NOBODY,         true); 
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
    curl_setopt($ch, CURLOPT_TIMEOUT,        15); 
    $r = curl_exec($ch); 
    $r = split("\n", $r); 
    return $r; 
} 

function getNextLocation($headers) { 
    $array = $headers; 
    $count = count($array); 
    for($i=0; $i < $count; $i++) { 
        if(strpos($array[$i], "ocation:")) { 
            $url = substr($array[$i], 10); 
        } 
    } 
    if($url) { 
        return $url; 
    } else { 
        return 0; 
    } 
} 

function getFinalPage($url) {
    $go = 1; 
    $i = 1; 
    while($go && $i < 6) { 
        $headers = getHeadersCurl($url); 
        $go = getNextLocation($headers); 
        if($go) { 
            $url = $go; 
        } 
        $i++;
    }
    return $url; 
} 

echo getFinalPage("http://wave.google.com/");

?>

Link to comment
https://forums.phpfreaks.com/topic/183865-php-link-checker/#findComment-970623
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.