Submit form only one time per day for one IP

PHP coding talk.

Moderator: Moderators

Submit form only one time per day for one IP

Postby Stryker on Wed Feb 28, 2007 4:48 pm

Hello, i dont know how to modify this code..
Code: Select all
<?/*
version 0.1
Build by chris mccabe- under the gpl license
for updates and news or if you have feedback
http://scripts.maxersmix.com

main page- things to edit include the advertiser code on line 35
*/?>
<header>

<title>Example link dump scripts.maxersmix.com</title>


</header>
<font face="Geneva, Arial, Helvetica, sans-serif">
<h1 align="center"></h1>
<center>

<?
  include("dbinfo.php");
$x = 0;
$y = 30;

do{

$sql = "SELECT url, title, date FROM `links` ORDER BY date DESC LIMIT ".$x.", ".$y.";";
$rs = mysql_query($sql);
echo mysql_error();
$nr = mysql_num_rows($rs);

while($row = mysql_fetch_row($rs)){
     echo "<a href=\"".$row[0]."\">".$row[1]."</a> ".$row[2]."\n<br>\n";
}

if($nr !=0){echo "<p>Advertise code here</p>";
}
$x = $x + 30;
$y = $y + 30;
} while($nr!=0);


mysql_close();
?>


<form name="form1" method="post" action="process.php">
  Title
  <input name="Link_title" type="text" id="Link_title2">
  Link
  <input name="Link" type="text" id="Link2">
  <input type="submit" name="Submit" value="Add">
</form>
</font>
<p>

</center>

I need to add there a function that will allow to submit the form on index only once per day.. if someone try it second time from the same IP as it was before, it will say "You are not allowed to submit the form again this day."
Any ideas?
User avatar
Stryker
Registered User
Registered User
 
Posts: 1318
Joined: Mon Aug 29, 2005 7:54 am
Location: ------------

Postby PostBot on Wed Feb 28, 2007 6:19 pm

Simple method without using database: create directory "cache" and make it writable, then in script that adds item to database add this:
Code: Select all
$f = @fopen('cache/ip_' . $_SERVER['REMOTE_ADDR'], 'w');
@fputs($f, time());
@fclose($f);
@chmod('cache/ip_' . $_SERVER['REMOTE_ADDR'], 0777);


Then in your script use this:
Code: Select all
if(@file_exists('cache/ip_' . $_SERVER['REMOTE_ADDR']) && @filemtime('cache/ip_' . $_SERVER['REMOTE_ADDR']) > (time() - 86400))
{
  die('You are not allowed to submit  the form again this day.');
}
Do NOT pm me, I don't visit this forum anymore, don't own it, don't provide any support and don't moderate.
User avatar
PostBot
Moderator
Moderator
 
Posts: 10659
Joined: Sat Aug 02, 2003 3:52 pm
Location: Mars

Postby Stryker on Thu Mar 01, 2007 5:17 am

great, thanks :) i was wondering how to create something wthout using DB...
User avatar
Stryker
Registered User
Registered User
 
Posts: 1318
Joined: Mon Aug 29, 2005 7:54 am
Location: ------------


Return to PHP Programming

Who is online

Users browsing this forum: No registered users and 2 guests

cron