Forum Moderators: open

Message Too Old, No Replies

ASP email form - prevent multiple emails or IPs?

         

opaque

5:56 pm on Dec 9, 2004 (gmt 0)

10+ Year Member



I use a basic ASP form that emails results of a survey form to a client. They now want me to prevent multiple entries based on email or IP address.

I assume this needs a database of created somehow, and is not an easy fix? This is a one time thing, and the client wants to know if it can be added easily, or not to bother.

I researched online but couldn't find a definitive answer, I'd appreciate any insights.

Easy_Coder

10:27 pm on Dec 9, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Create yourself a table that can hold the ip addys.

Write a routine that accepts the ip addy as a paramter and returns true or false based on existance. Here's an example to get you thinking about it(not tested).

Public Function IsNewPost(in_ipAddy)

Dim internal_IpAddy
Dim retVal

internal_IpAddy = in_ipAddy

If IsNull(internal_IpAddy) Or internal_IpAddy = "" Then
retVal = False
Else
Set oC = Server.CreateObject("adodb.connection")
oC.Open YOURDSN

Set oCMD = Server.CreateObject("adodb.command")
With oCMD
.CommandType = adCmdStoredProc
.CommandText = "sprocname"
.Parameters.Append .CreateParameter("@paramname", adVarchar, adParamInput, 15, internal_IpAddy )
.Parameters.Append .CreateParameter("@sprocResult", adInteger, adParamOutput, , returnResult)
.ActiveConnection = oC
.Execute()
returnResult = .Parameters("@sprocResult").Value
End With
Set oCMD = Nothing
oC.Close
Set oC = Nothing

If returnResult = "1" Or returnResult = 1 Then
retVal = False
Else
retVal = True
End If

End If

IsNewPost = retVal
End Function

Your sproc could look something along these lines (not tested):
create procedure userCheck
@paramname varchar(15),
@sprocResult int output
as
if exists(select ip from table where ip = @paramname)
begin
set @sprocResult = 1
end
else
begin
set @sprocResult = 0
end

Your asp call would look something like this (dbl check that server variable there is more then 1 which will return the ip address):

Dim bIsUserUnique
bIsUserUnique = IsNewPost(Request.ServerVariables("REMOTE_ADDR"))

Then just do your work based on the value of bIsUserUnique