<?PHP
/**
Copyright (C) 2008 ionix Limited
http://www.ionix.ltd.uk/
This script was written by ionix Limited, and was distributed
via the OpenCrypt.com Blog.
PHP Function for Reciprocal Linkback Checking
http://www.OpenCrypt.com/blog.php?a=28
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2 of
the License, or any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
GNU GPL License
http://www.opensource.org/licenses/gpl-license.php
*/
ini_set('error_reporting', E_ALL | E_STRICT);
ini_set('display_errors', 'On');
#ini_set('log_errors', 'On');
#ini_set('error_log', 'C:\XAMPP\xampp\htdocs\i\errors.log');
$field = "";
$global = "";
function reciprocal_linkback($check_url, $link, $strict = "0") {
global $global;
global $field;
$field['hostname'] = "";
$field['hostname_port'] = "80";
$field['result'] = "0";
preg_match("/^(http:\/\/)?([^\/]+)/i",$check_url, $field['hostname']);
$field['hostname_short'] = $field['hostname'][2];
$field['hostname_end'] = str_replace($field['hostname'][0], "", $check_url); # We don't want http://, we want the domain
$field['url_get'] = fsockopen($field['hostname_short'], $field['hostname_port']); # Connect to domain
if ($field['url_get']) { # We're connected...
if(trim($field['hostname_end'])=="") { # No filename, add a slash to end URL
$field['hostname_page'] = "/";
} else {
$field['hostname_page'] = $field['hostname_end']; # Filename
}
fputs($field['url_get'], "GET ".$field['hostname_page']." HTTP/1.0\r\nHost: ".$field['hostname_short']."\r\n\r\n"); # Request page from domain
$field['url_content'] = "";
while(!feof($field['url_get'])) { # Get data by line and store
$field['url_content'] .= fgets($field['url_get'], 10240);
}
if (eregi($link, $field['url_content'])) { # Can we find the URL in the page?
if ("$strict"=="1") { # Check for nofollow
$field['result'] = "1"; # Success, we have a link, now check for nofollow
$field['link_position'] = strpos($field['url_content'], $link); # Find position of URL being checked
$field['link_html_end'] = substr($field['url_content'],($field['link_position'] + strlen($link)),200); # Get HTML after URL
$field['link_html_start'] = substr($field['url_content'],($field['link_position'] - strlen($link) - 100),200); # Get HTML before URL
$field['link_html_end_explode'] = explode(">",$field['link_html_end']);
$field['link_html_start_explode'] = explode("<",$field['link_html_start']);
$link_html_start_count = count($field['link_html_start_explode']) - 1;
$field['link_html_start_explode'] = explode("=",$field['link_html_start_explode'][$link_html_start_count]);
$field['link_html_tag'] = $field['link_html_end_explode'][0].$field['link_html_start_explode'][0]; # Get link HTML, without URL and surrounding HTML
if (eregi("nofollow", $field['link_html_tag'])) { # Can we find a nofollow tag in link HTML?
$field['result'] = "0"; # Nofollow tag found
}
} else {
$field['result'] = "1"; # Success, we have a link, but nofollow not checked
}
}
fclose($field['url_get']);
} else {
$field['result'] = "2"; # Cannot read page
}
return $field['result'];
}
?>