您的位置:首页 > 其它

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

2011-10-31 14:20 218 查看
<?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 文件名或路径
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐