PHP Classes

File: index.php

Recommend this page to a friend!
  Classes of Nico den Boer   Anti-Harvest Download   index.php   Download  
File: index.php
Role: Example script
Content type: text/plain
Description: Usage example
Class: Anti-Harvest Download
Serve files for download preventing harvesting
Author: By
Last change:
Date: 13 years ago
Size: 2,328 bytes


Class file image Download
 * <p>
 * Script to safely serve a file for download.
 * And, most important, block downloads for bots to save bandwidth on our server
 * </p>
 * <p>
 * No harvesting allowed!
 * </p>
 * <p>
 * Usage:
 * </p>
 * <ul>
 * <li>Upload this script to your webserver, for example in /var/www/</li>
 * <li>Fill in the config section</li>
 * <li>Add links to your web pages, like <a href="">Download</a></li>
 * <li>Use a good tool like <a href="">webalizer</a> to analyze the traffic</a></li>
 * <li>Some time, keep a close look on low level to your web server logs. Check all succeeded downloads, to
 * be sure there are no more bots downloading your prohibited files.</li>
 * <li>If you have <a href=""><redis</a> (in Ubuntu repository as redis-server) installed on
 * your server, then this script can also keep track of the number of downloads, so users which are
 * harvesting but not identified as bots will be blocked too.
 * See <a href="">predis</a> for PHP client</li>
 * </ul>
 * <p>
 * This script written using the (free and OpenSource) ShishKabab PHP IDE,
 * <a href=""></a>
 * <p>
 * @author Nico den Boer <>, <>, <>
 * @version 1.0.1
 * @package AntiHarvestDownload

 * Class with protoctor
require(dirname(__FILE__) . '/');

$p = new protector();

// Path where the files to download actually are

// If you like, set user agents known as bots.
// See constructor of class about the format of the array
// $p->setAgents(array(
// ));

// If you like, set hosts known as bots
// See constructor of class about the format of the array
// $p->setHosts(array(
// ));

// If you like, you can use redis for memcaching to detect harvesting:
// $p->setPredis(
// '/tmp/libs/predis/Predis.php',
// 5 * 60, // all visits of more than 5 minutes back will be ignored
// 5 // if >5 visits during the timeframe above (5 minutes), then we have found a bot
// );

// In this case, pay special attention to line 240 in the class file!