homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Gold Sponsor 2015!
Home / Forums Index / Marketing and Biz Dev / Link Development
Forum Library, Charter, Moderators: martinibuster

Link Development Forum

PHP script to find all sites hot linking your images

5+ Year Member

Msg#: 4227893 posted 3:11 am on Nov 8, 2010 (gmt 0)

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.

php -f hotLink.php > myHotLinkList.txt


$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]



5+ Year Member

Msg#: 4227893 posted 3:17 am on Nov 8, 2010 (gmt 0)

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

Global Options:
 top home search open messages active posts  

Home / Forums Index / Marketing and Biz Dev / Link Development
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved