嗨,大家好我有這樣的代碼,檢查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