如何创建反向链接检查器

时间:2014-04-23 12:04:42

标签: php json codeigniter

我正在尝试在codeigniter中获得结果,但此代码不输出任何内容。 有没有人在codeigniter中有这个解决方案。 我需要一些提示。

$url = "https://ajax.googleapis.com/ajax/services/search/web?v=1.0&"
     . "q=Paris%20Hilton&userip=USERS-IP-ADDRESS";

// sendRequest
// note how referer is set manually
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_REFERER, /* Enter the URL of your site here */);
$body = curl_exec($ch);
curl_close($ch);

// now, process the JSON string
$json = json_decode($body);
// now have some fun with the results...

1 个答案:

答案 0 :(得分:3)

我有一个反向链接检查器使用curl你进入你的网站,你要检查的网站可能是你可以从这个工作

<div id="content">

  <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">

      <label>Target URL</label><input type="text" name="url" class="url" value="http://www." /><br/>

          <label>Your URL &nbsp;</label>  <input type="thereurl" name="thereurl" class="url" value="http://www."/>

      <input type="hidden" name="secureurl" value="1"/>

      <input type="submit" name="query" value="Check Links" class="button"/>

    </form>

<?php

  if(isset($_POST['query']))
  {

    $error=1;                      

    $target_url = $_POST['url'];

    $url2=$_POST['thereurl'];

    $userAgent = 'Googlebot/2.1 (http://www.googlebot.com/bot.html)';

    // make the cURL request to $target_url   

    $ch = curl_init();



    curl_setopt($ch, CURLOPT_USERAGENT, $userAgent);



    curl_setopt($ch, CURLOPT_URL,$target_url);



    curl_setopt($ch, CURLOPT_FAILONERROR, true);



    // curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);



    curl_setopt($ch, CURLOPT_AUTOREFERER, true);



    curl_setopt($ch, CURLOPT_RETURNTRANSFER,true);



    curl_setopt($ch, CURLOPT_TIMEOUT, 10);



    $html= curl_exec($ch);



if (!$html) {

    echo "<br />cURL error number:" .curl_errno($ch);

    echo "<br />cURL error:" . curl_error($ch);

    exit; 

}

// parse the html into a DOMDocument

$dom = new DOMDocument();

@$dom->loadHTML($html);

$xpath = new DOMXPath($dom);

$hrefs = $xpath->evaluate("/html/body//a");

for ($i = 0; $i < $hrefs->length; $i++) {

  $href = $hrefs->item($i);

  $url = $href->getAttribute('href');

  $rel = $href->getAttribute('rel');

  $length=strlen($url2);

  $changethis=substr($url2,0 , $length);

  $length2=strlen($url);

  $changethis2=substr($url,0 , $length);

  if($changethis2==$changethis)
  {

      echo "<br />Link: $url <strong>$rel</strong> was found backlinking your URL";

      $error=0;

  }
} //end loop

if($error <>0) {
  echo "No Backlink Was Found";        
}
echo "</div>";

  }//end if isset



?>

</div>

希望你能利用其中的一些