Have an idea?

Visit Sawtooth Software Feedback to share your ideas on how we can improve our products.

Block dublicate ip adress

Hi,

I want to block if the ip adress is used before in the survey. Is it possible to do it?

Many thanks...
asked May 20 by Hüseyin (190 points)

1 Answer

0 votes
This skip logic should fire for repeated IP addresses:

Begin Unverified Perl
# Parameters
my $table = '';
 
my $databaseName = '';
my $databaseUser = '';
my $databasePass = '';
my $databaseHost = '';
 
# IP Address
my $ip = GETVALUE('sys_IPAddress');
 
# Read database
my $dbh = DBI->connect('dbi:mysql:' . $databaseName . ':' . $databaseHost, $databaseUser, $databasePass);
my $sth = $dbh->prepare('SELECT `sys_IPAddress` FROM `' . $table . '` WHERE `sys_IPAddress` IS NOT NULL AND `sys_IPAddress` <> "" AND `sys_RespStatus` IS NOT NULL');
$sth->execute();
 
my $included = 0;
while (my $row = $sth->fetchrow_arrayref()) {
    my $resp = $row->[0];
    if ($resp eq $ip) {
        $included = 1;
        last;
    }
}
 
$sth->finish;
$dbh->disconnect;
 
# Return
return $included;
End Unverified


Lines 3 - 8 must be updated with your database table name and database credentials.  See the instructions here:

https://sawtoothsoftware.com/community-question-library/1752-read-database
answered May 20 by Zachary Platinum Sawtooth Software, Inc. (120,900 points)
""""Sawtooth Error # """"132 It gives this.
132 is an error in unverified Perl.  You will need to look in your admin module to get the full error message.
Thank you for sharing the code
Correct me if I am wrong, so I should add this code to the skiplogic of one of my questions & preferably on the earliest pages of the survey, correct?
It is intended as skip logic, for a skip that will skip repeated IP addresses to a terminate question most likely.  It should be used whenever you want to catch repeated IP addresses, which I would assume would be early in the questionnaire.
...