嗨,大家好我有这样的代码,检查linkback:传递查询字符串来形成选择选项
$reciprocal_linkback = reciprocal_linkback("$contenturl","http://www.mydomain.com",1);
if ("$reciprocal_linkback"=="0") {
$contenturl
是会反对我的网站进行检查URL(http://www.mydomain.com)
的问题是,我需要检查网址和主页面。 我用这个代码:
$parse = parse_url($contenturl);
而结果在最后会是这样:
$parse = parse_url($contenturl);
$reciprocal_linkback = reciprocal_linkback("$contenturl, $parse","http://www.mydomain.com",1);
if ("$reciprocal_linkback"=="0") {
林不知道如何使用多个变量,例如$contenturl, $parse
,所以我可以核对我的域名这两个链接。
我将不胜感激任何帮助。
Siconerely。
编辑:继承人的功能
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'];
}
以及完整的代码我上面提及:
// Check to see if have backlink and nofollow atribute
$reciprocal_linkback = reciprocal_linkback("$contenturl","http://www.dumpvid.com",1);
if ("$reciprocal_linkback"=="0") {
$_SESSION['submitstatus'] = "<div class=error><b>Error:</b> Backlink was not found, or nofollow detected.</div> ";
header('Location: '.$frompage.'');
exit;
}
我需要检查它的网址本身来自同一URL的域。
那就是为什么我使用$ parse = parse_url($ contenturl);仅在domain.tld中转换url,但dint起作用。
你为什么把变量引号?它不应该是这样的:'reciprocal_linkback($ contenturl,$ parse,“http://www.mydomain.com”,1)'?如果你要发布这个函数本身,这将会很有用。如果'$ contenturl'和'$ parse'都是链接,并且你想在这个函数中检查它们,你应该调用它两次或修改函数本身。 – 2011-12-26 15:04:52
我从教程中学到了这段代码,它的工作很好我猜,我只是不知道如何改变它以便实现我的需求,任何消化都将不胜感激 – 2011-12-26 20:28:52
我更新了tmy的第一篇文章并添加了完整的功能,以便您可以分析更好。现在感谢 – 2011-12-26 20:50:04