Jump to content

SESSIONs to stop repetitive form submission?


helraizer

Recommended Posts

Hi Folks,

 

I have a comment system on my website, but i don't use a database for it, so I don't really want to set one up. At the moment, on the comment submission if the user refreshes they can flood the comments page.. Using sessions, how would I stop the user posting more than 2 times in a minute (or one time in 30 seconds, if it's easier..

 

Hope that made sense,

Sam

So if you're not using a database, what are you using? Files?

 

I have a file called '.entries', which is written to each time a comment is posted. Each comment is seperated with ### so it explodes it at the ### and loads each comment into a div.

 

If you want the code, just say. Although, there is a lot of it.

 

Sam

you can set a session variable with the current time.  if the timestamp is less than 30 seconds old, don't show the form (also add a check into the posting process, because they may find a way around it):

 

$_SESSION['antispamification'] = time();

if ((time() - $_SESSION['antispamification']) >= 30)
{
  // show form
}

 

you'll need to follow all the usual session rules.  for those, have a peek at a beginner's sessions tutorial.  note that time() is a timestamp in seconds, so adjust the number appropriately if you wish to lengthen the "cooldown" phase.

It depends. If you have multiple things people comment on, then you can restrict them from commenting on the same thing twice. I'm sure going to a page and back would be a pain for the user so they wouldn't bother.

 

You can do this with session without a problem.

 

On another note, your method of the commenting system (with the file write each time) is very inefficient. Mysql is the answer - unless you have reason not to. It would be a lot faster and easier to sort.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.