here it is:
the current setup involves 3 pages:
blocked.php (performs all the checks)
index.php (holds the form)
doimg.php (generates the number image)
blocked.php
<?php
session_start();
$IMGVER_EnteredText = $_REQUEST["txtCode"];
$IMGVER_RandomText = $HTTP_SESSION_VARS["IMGVER_RndText"];
//$IP = getenv("REMOTE_ADDR");
$bip = "74.41.108.41"; //IP Address to block
$bea = "bob@att.com"; //Email Address blocked.
$bdom = "spam.com"; //Domain of Emails to be blocked.
//$checklevel = "9"; //Level to check for blocks (1=IP), (3=full email), (5=email domain)
//$bsnt = "bob@aol.com";
//$bsnt = "spam.com";
$bsnt = $_REQUEST["bsnt"];
$checklevel = $_REQUEST["filter"];
$IP = $_REQUEST["IP"];
$message = $_REQUEST["bsmg"];
if ($IP =="") {$IP = getenv("REMOTE_ADDR");}
if ($bsnt =="") {header("Location: http://www.scriptinphp.com/filter");}
if ($message =="") {header("Location: http://www.scriptinphp.com/filter");}
if ($IMGVER_EnteredText == "") {header("Location: http://www.scriptinphp.com/filter");}
if ($checklevel =="") { $checklevel = "20";}
//$bsnt = $_REQUEST["bsnt"];
//echo "email used = '" . $bsnt . "'<BR>" . "email blocked = '" . $bea . "'<BR>" . "IP used = '" . $IP . "'<BR>" ."IP Blocked = '" . $bip . "'<BR>" . "domain blocked = '" . $bdom . "'<BR>";
list ( $Username, $Domain ) = split ("@",$bsnt);
echo "<BR><BR><BR><BR>";
//Block By IP Address
if ($checklevel == "1" || $checklevel=="4" || $checklevel=="6" ||$checklevel=="9" || $checklevel=="20"){
if ($IP == $bip) {die('Not authorized - <font color=red>Due to IP address Filter</font>.'); }
echo "IP address allowed<BR>";}
//Blocked EMAIL addresses
if ($checklevel == "3" || $checklevel=="4" || $checklevel=="8" ||$checklevel=="9" || $checklevel=="20"){
if ($bea == $bsnt) {die('Not authorized - <font color=red>Email Address Not allowed to send messages.</font>.'); }
echo "Email address allowed<BR>";}
//Blocked EMAIL domain
if ($checklevel == "5" || $checklevel=="6" || $checklevel=="8" ||$checklevel=="9" || $checklevel=="20"){
if ($bdom == $Domain) {die('Not authorized - <font color=red>Email Domain Not allowed to send messages. </font>.'); }
echo "Email Domain allowed<BR>";}
if ($checklevel == "11" || $checklevel=="12" || $checklevel=="14" ||$checklevel=="15" || $checklevel=="16" || $checklevel=="19" || $checklevel=="20" ){
if ($IMGVER_EnteredText == $IMGVER_RandomText) {
echo "Code Accepted<BR>";
/* ENTER YOUR MESSAGE ABOVE OR MAKE THIS FILE A FUNCTION
** AND USE RETURN INSTEAD! */
} else {die('Not authorized - <font color=red>Incorrect code entered.</font>.'); }
}
//change to code for accepted message rules (to que for sending).
echo "All checks Passes, you message will now be set into the que for sending after moderator approves it.";
echo "<BR>The message was<HR>$message<HR>";
?>
<a href="index.php">Test again</a>
index.php
<?php
session_start();
$IMGVER_TempString="";
for ($i = 1; $i <= 6; $i++) {
$IMGVER_TempString .= GetRandomChar();
}
$HTTP_SESSION_VARS["IMGVER_RndText"] = $IMGVER_TempString;
function GetRandomChar() {
mt_srand((double)microtime()*1000000);
$IMGVER_RandVal = mt_rand(1,3);
switch ($IMGVER_RandVal) {
case 1:
$IMGVER_RandVal = mt_rand(97, 122);
break;
case 2:
$IMGVER_RandVal = mt_rand(48, 57);
break;
case 3:
$IMGVER_RandVal = mt_rand(65, 90);
break;
}
return chr($IMGVER_RandVal);
}
?>
<head>
<style>
.rightborder {
border-right: 1px solid #0000ff;
}
.leftborder {
border-left: 1px solid #000000;
border-style: dashed;
}
</style>
</head>
<body>
</body>
</html>
<form action="block.php">
<table align="center">
<tr><td class="rightborder" ><Font color="Green">Filter Level ID's</font><font color=green size='-1'><BR>1=IP only<BR>3=email address only<BR>4=IP + Email Address<BR>5=Email Domain Only<BR>6=IP+EMAIL domain<BR>8=Email Address + Domain<BR>9=IP, Email address, Domain</font><HR><font color=red>Current Blocks</font>
<font color="Red" size='-1'>IP Blocked: 74.41.108.41<BR>EMAIL BLOCKED:bob@att.com<BR>DOMAIN BLOCKED: spam.com</font>
<BR>no message or email address sent will<BR>reset the form. <BR>no IP entered will add the real IP<BR>No check level will set to level 9.<BR>
</td><td>
<table align="center">
<tr><td>Filter Level</td><td><input type="text" name="filter"></td></tr>
<tr><td colspan="2"> </td></tr>
<tr><td>Simulate IP address</td><td><input type="text" name="IP"></td></tr>
<tr><td colspan="2"> </td></tr>
<tr><td>From Field</td><td><input type="text" name="bsnt"></td></tr>
<tr><td>Message</td><td><textarea name="bsmg"></textarea></td></tr>
<tr><td colspan="2"><div align="right"><font size="2" face="Verdana, Arial, Helvetica, sans-serif"><img src="doimg.php?<?php echo SID ?>" /></font></div></td></tr>
<tr><td><font size="2" face="Verdana, Arial, Helvetica, sans-serif">Enter the code
here: </font> </td><td> <div align="right"><input name="txtCode" type="text" id="txtCode" size="30" /></div></td></tr>
<tr><td colspan="2"><div align="center"><input type="submit"></div></td></tr>
</table>
</td></tr></table>
</form>
doimg.php
<?php
/*
** This function generates a picture with a text passed to it.
**
** Written by Alexander Graf, 10/04/2002
** AlexGraf@web.de
*/
// Create the image with width=150 and height=40
$IMGVER_IMAGE = imagecreate(150,40);
// Allocate two colors (Black & White)
// This uses the RGB names of the colors
$IMGVER_COLOR_BLACK = imagecolorallocate ($IMGVER_IMAGE, 0, 0, 0);
$IMGVER_COLOR_WHITE = imagecolorallocate ($IMGVER_IMAGE, 255, 255, 255);
// Flood Fill our image with black
imagefill($IMGVER_IMAGE, 0, 0, $IMGVER_COLOR_BLACK);
// This handles our session. We get the random text that
// was stored in our session var on the first page.
session_start();
$IMGVER_RandomText = $HTTP_SESSION_VARS["IMGVER_RndText"];
// Since our Text had 6 chars (we defined this not to be longer)
// we now write the 6 random chars in our picture
// For those who don“t know: You can access the third character
//in a string easily by typing $myString[2];
imagechar($IMGVER_IMAGE, 4, 20, 13, $IMGVER_RandomText[0] ,$IMGVER_COLOR_WHITE);
imagechar($IMGVER_IMAGE, 5, 40, 13, $IMGVER_RandomText[1] ,$IMGVER_COLOR_WHITE);
imagechar($IMGVER_IMAGE, 3, 60, 13, $IMGVER_RandomText[2] ,$IMGVER_COLOR_WHITE);
imagechar($IMGVER_IMAGE, 4, 80, 13, $IMGVER_RandomText[3] ,$IMGVER_COLOR_WHITE);
imagechar($IMGVER_IMAGE, 5, 100, 13, $IMGVER_RandomText[4] ,$IMGVER_COLOR_WHITE);
imagechar($IMGVER_IMAGE, 3, 120, 13, $IMGVER_RandomText[5] ,$IMGVER_COLOR_WHITE);
//Now we send the picture to the Browser
header("Content-type: image/jpeg");
imagejpeg($IMGVER_IMAGE);
?>
please comment on the coding if anyone sees any method of cleaning up / securing the code better please let me know.
this is not my final version. but does give a good foundation.
in the final version I have modified it slightly, created an admin panel, and it uses database stored in a database.