插件43:可以自动返回的链接

本文介绍了一个自动回链插件的功能,它接受一个文件名作为输入,该文件记录了所有链接到当前网页的网站信息。插件通过解析此文件,输出内部链接及其来源网址。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

<?php // Plug-in 43: Auto Back Links

$logfile = "refererlog";
echo "Referring URLs in logfile '$logfile':<br /><br />";

$results = PIPHP_AutoBackLinks($logfile);
if (!$results[0]) echo "No referring URLs";
else foreach ($results[1] as $result)
{
   $title = PIPHP_GetTitleFromURL($result);
   echo "<a href='$result'>";
   echo $title ? $title : $result;
   echo "</a><br />";
}

function PIPHP_AutoBackLinks($filename)
{
   // Plug-in 42: Auto Back Links
   //
   // This plug-in takes the filename of a log file, as
   // supplied to Plug-in 30, PIPHP_RefererLog(), and returns
   // a two element array where the first value is TRUE and
   // the second is an array of inbound links sorted by the
   // amount of hits received. If there are no links only a
   // single element array is returned, with the value FALSE.
   // The argument required is:
   //
   //    $filename: The name of a log file

   if (!file_exists($filename)) return array(FALSE);
   
   $inbound = array();
   $logfile = file_get_contents($filename);
   $links   = explode("\n", rtrim($logfile));
   $links   = array_count_values($links);
   arsort($links, SORT_NUMERIC);
   
   foreach ($links as $key => $val)
      if ($key != " No Referer")
         $inbound[] = $key;

   return array(TRUE, $inbound);
}

// The function below is repeated here to ensure that the
// main function (which relies on it) has access to it

function PIPHP_GetTitleFromURL($page)
{
   // Plug-in 42: Get Title From URL
   //
   // This plug-in takes the URL of a web page and returns that
   // page's title. If the page cannot be loaded then FALSE is
   // returned. The argument required is:
   //
   //    $page: The URL of a page, including the preceding
   //           http://

   $contents = @file_get_contents($page);
   if (!$contents) return FALSE;
   
   preg_match("/<title>(.*)<\/title>/i", $contents, $matches);

   if (count($matches)) return $matches[1];
   else return FALSE;
}

?>

插件说明:

本插件接受一个文件名,他保存了所有链接到当前网页的网站的详细信息。这个文件名由插件30的PIPHP_RefererLog()函数创建的。

本插件需要以下参数

$filename 文件名或路径

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值