Page 1 of 1
form blocking
Posted: Sat Nov 01, 2003 10:20 pm
by FormatteD_C
Hi,
I don't really know how to code in PHP but I know how to edit somethings in PHP and what not. Anyway, I have a PHP code that grabs the persons IP and saves it to a text file after they submit a form. And I need another code that will block the IP from submitting the form again. (I know this will obviously not work with dynamic IPs but it will make it harder for them to spam) Like maybe sending them to another page saying "sorry you already submitted" and I have no idea how to code this, thanks
Posted: Sat Nov 01, 2003 10:40 pm
by d3ad1ysp0rk
so what do you need help with?
I'm not really sure what you have yet, and im not gonna send you tutorials or sample code for something you've already done

Sorry!
Posted: Sat Nov 01, 2003 10:47 pm
by FormatteD_C
ok this code right here his within a php form script, its near the end after all the functions are completed
<?php
$found = "false";
$filename = "iplist.txt";
if (file_exists ($filename))
{$fp = fopen($filename,"r+");}
else{$fp = fopen($filename,"w");}
$offset = 0;
$cnt = 1;
while ($row = fgets($fp,4096)) {
$cols = explode(";",$row);
if ($cols[0] == $HTTP_SERVER_VARS["REMOTE_ADDR"]){
$cols[1]++; // increase counter;
$cnt = $cols[1];
$cols[3] = date("M/d/Y_H:i:s"); //save hour minute seconds _ month date year
fseek($fp,$offset);
fputs($fp,implode(";",$cols));
$found = "true";
}
$offset = ftell($fp);
}
if ($found=="false"){
$cols = array($HTTP_SERVER_VARS["REMOTE_ADDR"],"\n");
fputs($fp,implode("",$cols));
}
fclose($fp);
?>
This is the script that logs the IP and and saves it to iplist.txt, that all works fine. (I realize some of the script above is unused, I just edited to get the IP)
But I want to put a PHP code in the page that contains my form which blocks the IPs in the iplist.txt from accessing the page
Posted: Sat Nov 01, 2003 11:02 pm
by d3ad1ysp0rk
I don't know the exact functions for each thing, so I'm just gonna give you the psuedo(sp?) code for it..
Code: Select all
<?PHP
$userip = get users IP;
$filename = fopen("iplist.txt", "r");
$ips(an array) = read file into array;
fclose($filename);
$ipsearch = array_search("$userip",$ips,true);
if(ipsearch=="true")
{
echo "sorry, you cannot fill out this form more than once..";
}
else
{
//display form
}
?>
hope thats what ur looking for..
Posted: Sat Nov 01, 2003 11:39 pm
by JAM
To show some more idea-code...
Code: Select all
function cleanup($a) { return trim($a); }
$array = file('ips.txt'); // read file into array
$array = array_map('cleanup', $array); // use a function on all values
echo 'Found match: '. (array_search($_SERVER['REMOTE_ADDR'], $array) > 0 ? 'YES' : 'NO');