Created
February 16, 2022 08:46
-
-
Save titomus/9ae92a28bb4850187211ab894df551ca to your computer and use it in GitHub Desktop.
Is alive backlink
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function is_alive_bl($url,$on){ | |
if (function_exists('curl_init')) { | |
$ch = curl_init(); | |
$options = array( | |
CURLOPT_URL => $on, | |
CURLOPT_HEADER => false, | |
CURLOPT_RETURNTRANSFER => true, | |
//CURLOPT_FOLLOWLOCATION => true, | |
CURLOPT_MAXREDIRS => 3, | |
CURLOPT_TIMEOUT => 20, | |
CURLOPT_SSL_VERIFYHOST => false, | |
CURLOPT_SSL_VERIFYPEER => false, | |
CURLOPT_USERAGENT => 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.133 Safari/537.36', | |
CURLOPT_HTTPHEADER => array('Connection: close', 'Cache-Control: no-cache'), | |
); | |
curl_setopt_array($ch, $options); | |
$data = curl_exec($ch); | |
} // No cURL, try file_get_contents | |
else { | |
$data = @file_get_contents($on); | |
} | |
// Did we succeed? | |
if ($data === false || strlen($data) < 1) { | |
return false; | |
} else { | |
// Convert all code to lowercase | |
$html = strtolower($data); | |
// Remove "https" and "www" for verification purposes | |
$site_url = str_replace(array('https://', 'http://www.'), array('http://', 'http://'), strtolower($url)); | |
$site_url = @trim($site_url, '/'); | |
// Can we find the reciprocal link? | |
if (preg_match_all('/<a\s[^>]*href=([\"\']??)([^" >]*?)\\1([^>]*)>/siU', $html, $matches, PREG_SET_ORDER)) { | |
//echo '<pre>';var_dump($matches); | |
foreach ($matches as $match) { | |
$match[2] = str_replace(array('https://', 'http://www.'), array('http://', 'http://'), $match[2]); | |
// on vire les repartoire et les param get | |
$match[2] = @explode('?', $match[2], 2)[0]; | |
$formatmatch = @trim($match[2],'/'); | |
//echo $formatmatch.' == '.$site_url.chr(10); | |
if ( $formatmatch == $site_url) { | |
// All OK | |
return true; | |
} | |
} | |
} | |
// No reciprocal link found | |
return false; | |
} | |
} | |
// Utilisation | |
$url = 'URL DE VOTRE SITE'; | |
$on = 'URL DE LA PAGE A VERIFIER'; | |
if (is_alive_bl($url,$on) != false){ | |
echo $url. ' Trouvé sur '.$on; | |
}else{ | |
echo "Erreur de scrape"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment