Jump to content

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.