Welcome to WebmasterWorld Guest from 107.21.159.218

Forum Moderators: martinibuster

Message Too Old, No Replies

PHP script to find all sites hot linking your images

     

janoss

3:11 am on Nov 8, 2010 (gmt 0)

10+ Year Member



I started to notice some more hot linking by reading through my http access logs. My strategy is to allow the hot links and customize the image to which the external site is referring. I basically make an advertisement for my store based on the linked image.

Note that I do not want to go with the .htaccess hot-link rewrite rule since I want to customize the ad based on the external site.

I wanted a script to go through my access logs to pull out the hot linkers and dump it to a text file. Then I look at the image the are linking to and decide what I want to do with the image.

Anyway, I threw this together to help with the mission at hand. Hopefully others will find it useful and add to it.

Invocation
php -f hotLink.php > myHotLinkList.txt


<?php

$handle = @fopen("/var/log/httpd/access_log", "r"); // Open file form read.

if ($handle) {
while (!feof($handle)) // Loop til end of file.
{
$buffer = fgets($handle, 4096); // Read a line.
if(preg_match('/GET \/images/',$buffer, $matches)) {

// This is my list of acceptable sites. If not in the list, then it is a non-approved hot lister.

if(preg_match('/customvictorymotorcycleparts|myklr650|kingpincruisers|cyclesolutions|google|ebay|aitsafe|\"-\"/i',$buffer, $matches)) {
// skip this record since it is an acceptable site.
} else {
echo $buffer;
}
}
}
fclose($handle); // Close the file.
}

?>

[edited by: janoss at 3:18 am (utc) on Nov 8, 2010]

janoss

3:17 am on Nov 8, 2010 (gmt 0)

10+ Year Member



For some reason the code tags did not keep the formatting of the code.
 

Featured Threads

Hot Threads This Week

Hot Threads This Month