Print Page | Close Window

Prevent multiple postings

Printed From: Web Wiz Forums
Category: General Discussion
Forum Name: Classic ASP Discussion
Forum Description: Discussion on Active Server Pages (Classic ASP).
URL: https://forums.webwiz.net/forum_posts.asp?TID=7698
Printed Date: 31 March 2026 at 11:22pm
Software Version: Web Wiz Forums 12.08 - https://www.webwizforums.com


Topic: Prevent multiple postings
Posted By: Eagle
Subject: Prevent multiple postings
Date Posted: 28 November 2003 at 4:44pm

I’m new with all this and I’m trying to prevent the users of my ASP forms to do multiple postings in a few seconds. I’ve found an ASP code that would work but the problem is that it uses a database and I’ve never done that. I don’t even know how to create it or to make the table that it requires. Could someone help me with this stuff, please? Here is the code:

 

<%
      ' This assumes the following:
      ' The database ~abuseConnection~ contains a table called 'abuse'
      ' and this table has two columns, 'ip' and 'ok.' IP contains the
      ' IP address of the poster, 'ok' is when the user may post again.
      
      ' Save the IP address in a variable.
      abuseIP = request.servervariables("REMOTE_HOST")
      ' Enter your database connection string
      abuseConnection = ""
      ' You can add this code as a type of 'last seen function' too,
      ' add a 'doing' table and call this sub with checkAbuse("Posting a message")
      ' or something. For now, just IP and OK will work. Make sure to
      ' include the final WHERE statement.
      abuseSQL = "SELECT ip, ok from abuse where ip = '" & abuseIP & "'"
      ' How many seconds between actions? I use 30 seconds on my site, but its up to you.
      abuseWait = 30
      ' Where do we direct the user if they fail the check?
      abuseDirect = "toofast.asp"
      
      ' Connect to the databse.
      Set abuseConnection = Server.CreateObject("ADODB.Connection")
      abuseConnection.Open abueConnection
      Set abuseRecordset = Server.CreateObject("ADODB.Recordset")
      abuseRecordset.open abuseSQL, abuseConnection, 3, 3
      
      ' If no records exist at all then the user is OK.
      ' All we have to do is add a record and set it for abuseWait seconds from now.
      if abuseRecordset.recordCount = 0 then
       abuseRecordset.addnew
        abuseRecordset("ip") = abuseIP
        abuseRecordset("ok") = dateadd("s", abuseWait, now)
       abuseRecordset.update
       returnValue = True
      else
      ' If a record exists, make sure that the "OK Time" is NOT greater than the
      ' current time. If it is, kick the user to another page, if not, reset the value.
      ' updte the time to 30s and return true.
       if abuseRecordset("ok") > now or isNull(abuseRecordset("ok")) then
        returnValue = False
       else
        abuseRecordset.update "ok", dateadd("s", abuseWait, now)
        returnValue = True
       end if
      end if
      
      abuseRecordset.close
      set abuseRecordset = Nothing
      abuseConnection.close
      set abuseConnection = Nothing
      
      If Not returnValue Then Response.Redirect(abuseDirect)
      ' You may want to turn this to a function for more versatility in your code.
      ' Just change the 'Sub's to 'Function's and add checkAbuse = returnValue.
      ' NOTE: This is really basic. You can add a counter, for example x posts in x seconds,
      ' as well as code to clean older entries. Maybe I'll do it if you REALLY like it :)
     End Sub
    %>




Replies:
Posted By: theSCIENTIST
Date Posted: 29 November 2003 at 1:21am

Humm, aren't you using wwforums? They already have that feature, go into the admin console and choose the Anti-Spam Configuration option.

If you are not using wwf, it can be done like this: When a post is created, it should write the poster ID and the time it was posted to the DB, when updating the DB, aslo write to the user cookie a new key (ie. antispam) and set the time, then, when the user trys to post again, check against the time he last posted and decide whether to allow or not.

There are other ways, like checking against the DB for the time he last posted.

It would help if you tell us what DB and forums you are using, maybe one of us can mod it for you.



Posted By: Semikolon
Date Posted: 29 November 2003 at 10:38am

hey you scientist..

Originally posted by theSCIENTIST theSCIENTIST wrote:

maybe one of us can mod it for you.

Dont say that.. if you say that some of us can mod it for him, ppl think that its just to command us to do it.. thats not the way its gonna be.. they should try themselves first, then ask for help..

but of course, if you want to code for ppl you dont know, thats up to you..



Posted By: theSCIENTIST
Date Posted: 30 November 2003 at 5:30am

Hi AnthraX,

You are right, I shouldn't said WE, and sometimes when I'm free not involved in any project I do provide simple solution for people, let's see what DB he is using, one should assume that since he's posting in this forums that he's using WWF and that feature is already present.




Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.08 - https://www.webwizforums.com
Copyright ©2001-2026 Web Wiz Ltd. - https://www.webwiz.net