Jump to content

[SOLVED] Verify that link exists


brooksh

Recommended Posts

How can I verify that my link exists on another site? I want to search the page and for the script to come back and say that it is there or not.

 


$handle = fopen("$url", "rb");
$contents = 'mylink.com';
while (!feof($handle)) {
  $contents .= fread($handle, 8192);
}

if($contents!=""){
echo "No";
} else {
echo "Yes";
fclose($handle);

Link to comment
https://forums.phpfreaks.com/topic/42562-solved-verify-that-link-exists/
Share on other sites

<?php
function check_back_link($remote_url, $your_link) {
    $match_pattern = preg_quote(rtrim($your_link, "/"), "/");
    $found = false;
    if ($handle = @fopen($remote_url, "r")) {
        while (!feof($handle)) {
            $part = fread($handle, 1024);
            if (preg_match("/<a(.*)href=[\"']".$match_pattern.
"(\/?)[\"'](.*)>(.*)<\/a>/", $part)) {
                $found = true;
                break;
            }
        }
        fclose($handle);
    }
    return $found;
}
// example:
//if (check_back_link("http://www.it-guru.co.uk", "http://www.it-guru.co.uk")) echo "link exists";
?>

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.