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
%>