<?php
/**
* MySQL Table Definition
*
* CREATE TABLE `sig` (
* `id` INT UNSIGNED NOT NULL AUTO_INCREMENT ,
* `ip` VARCHAR( 16 ) NOT NULL ,
* PRIMARY KEY ( `id` ) ,
* UNIQUE (
* `ip`
* )
* );
*
* Script first checks to see if the IP address has been added to
* a list of addresses which have requested not the see a random image.
* If they have then the blocked image is shown, if not then the
* contents of the folder which this file is in is read and an image
* is randomly selected, the proper headers sent and then the image
* data.
*/
mysql_pconnect("localhost","username","password");
mysql_select_db("database");
$addr = $_SERVER['REMOTE_ADDR'];
$query = mysql_query("SELECT `id` FROM sig WHERE `ip`='{$addr}'");
$rows = mysql_num_rows($query);
if($rows != 0) {
// No rows, ip address has not requested blocking
srand( time() );
$files = array();
if ($dir = @opendir(".")) {
while (($file = readdir($dir)) !== false) {
if ( eregi( '.(jpg|gif)$', $file ) ) {
$files[] = $file;
}
}
closedir($dir);
}
$file = $files[rand() % sizeof( $files )];
if ( eregi( '.jpg$', $file ) ) {
header( "Content-Type: image/jpeg" );
} else {
header( "Content-Type: image/gif" );
}
header( "Content-Length: " . filesize( $file ) );
readfile( $file );
} else {
header( "Content-Type: image/jpeg" );
header( "Content-Length: " . filesize("blocked.jpg"));
readfile( "blocked.jpg" );
}
?>