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
form blocking
Moderator: General Moderators
- FormatteD_C
- Forum Newbie
- Posts: 10
- Joined: Tue Oct 21, 2003 5:08 pm
- Location: Ohio
- Contact:
-
d3ad1ysp0rk
- Forum Donator
- Posts: 1661
- Joined: Mon Oct 20, 2003 8:31 pm
- Location: Maine, USA
- FormatteD_C
- Forum Newbie
- Posts: 10
- Joined: Tue Oct 21, 2003 5:08 pm
- Location: Ohio
- Contact:
Sorry!
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
<?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
-
d3ad1ysp0rk
- Forum Donator
- Posts: 1661
- Joined: Mon Oct 20, 2003 8:31 pm
- Location: Maine, USA
I don't know the exact functions for each thing, so I'm just gonna give you the psuedo(sp?) code for it..
hope thats what ur looking for..
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..
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');