An Idea of having one's site automatically crawl referrers for information.
If the site does this and information about it is printed out somewhere near the links, there is a possibility that site developers add a link to my site, to get a link to their site published on my site, without cost, and without marketing.
One could of course make the site send an email to the webmaster first, so he/she can check the referrer link, before permitting the request, in case of the referrer is an obscene site or something else that you would not want to have published.
A simple url is not very exiting, so her goes a method to browse the referrer and extract any occurrance of a title tag or a valid meta description of the site.
Also, the idea could be completed with more functionality, like searching the referrer site for a special description file, or something like a banner, located at a customiseable place.
It sounds good at least in my ears...
A way to get linked to from another site, since anyone would want to have a link to a site that gives a link to you. (at least in theory...)
Sounds a little bit complicated maybe. It took me 15 minutes to explain this to a friend.
Note, the actual intended functionality is not implemented, this is just the code browsing a remote site for info.
Here it goes, it is still very simple and contains a test form:
Code: Select all
<?php
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
function hostname($strURL){
preg_match("/\:\/\/([^\/]+)/",$strURL,$arrResult);
return $arrResult[1];
}
function ExamineURL($strURL){
echo "<pre style="background: #fee">";
$strPage = @file_get_contents($strURL) or ($Error = 1);
if (!$Error){
if(preg_match_all("/(?i)\<title\s*\>([^<]+)\<\/title\s*\>|\<meta\s+name=\"description\"\s*content=\"([^\"]+)\"\s*\/?\>/", $strPage, $arrResult)){
$arrReturn['URL'] = $strURL;
$arrReturn['URL'] = hostname($strURL);
echo "Examined URL: <a href=\"$strURL\">" . $strURL."</a><br>";
foreach ($arrResult as $patternOrder => $arrMatches){
foreach($arrMatches as $strMatch){
if ($patternOrder == 1 && strlen($strMatch)){
$arrReturn['title'] = $strMatch;
echo "Examined title: <b>" . $strMatch ."</b><br>" ;
}
if ($patternOrder == 2 && strlen($strMatch)){
$arrReturn['descr'] = $strMatch;
echo "Examined description: <b>" . $strMatch ."</b><br>" ;
}
}
}
return $arrReturn;
}
}else{
echo "Error! Could not open: <a href=\"$strURL\">" . $strURL."</a>";
}
echo "</p>";
}
?>
<form action="<?php echo basename($_SERVER['PHP_SELF'])?>" method="POST">
<input type="text" name="strURL" value="<?php echo strlen($_POST['strURL']) ? $_POST['strURL'] : "http://"?>">
<input type="submit" name="submit" value="Test URL"><br>
</form>
<?php
if (isset($_POST['strURL'])){
print_r(ExamineURL($_POST['strURL']));
}
if (strlen($_SERVER['HTTP_REFERER'])){
print_r(ExamineURL($_SERVER['HTTP_REFERER']));
}
?>