将查询字符串传递给表单选择选项

时间:2011-12-26 14:47:58

标签: php parsing variables

大家好我有这个检查链接的代码:

$reciprocal_linkback = reciprocal_linkback("$contenturl","http://www.mydomain.com",1);

if ("$reciprocal_linkback"=="0") {

$contenturl是将根据我的网站(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这样的多个变量,因此我可以针对我的域检查这两个链接。

我将不胜感激。

Sicnerely。

编辑:继承人的功能

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; 

}

我需要让它从同一个网址检查网址本身和域名。

这就是我使用$ parse = parse_url($ contenturl)的原因;仅转换domain.tld中的url,但dint工作。

1 个答案:

答案 0 :(得分:0)

你可以这样做:

$contenturl = "http://domain.com/video_content.html";
$parse = parse_url($contenturl);
$base_url = $parse["host"]; // domain.com

并称之为两次:

$linkback1 = reciprocal_linkback($contenturl, "http://www.mydomain.com", 1);
$linkback2 = reciprocal_linkback($base_url, "http://www.mydomain.com", 1);