The accessCount()
function is used to limit incorrect entries in a code query. Without a parameter, the function returns the number of previous attempts. If the parameter ban time
is specified, the counter is incremented by one.
int accessCount([int ban time])
Note: When querying participation codes, SoSci Survey automatically counts failed attempts. The accessCount()
function is only required if the query and check of codes is implemented manually.
Note: The function checks the multiple entry using both the current interview and the IP address. The ban entries are stored separately from the data collected, so that usually no personal data is processed within the meaning of the GDPR. However, the ban can be circumvented by an Internet proxy that accesses the questionnaire via different IP addresses.
Note: The function also creates an entry in the external blacklist, which may be used by the server to completely block an IP address for a longer period of time (server configuration: fail2ban for SoSci Survey).
This application example requires the following prerequisites:
On page 1 of the questionnaire, accessCount()
is first used to check whether a maximum of 5 failed attempts have been made. Depending on this, the input field or an error message is displayed. In the latter case, there is no “Next” button.
if (accessCount() > 5) { show('TC03'); // error message " too many attempts" buttonHide(); // hide buttons pageStop(); } else { show('TC01'); // Questions about the participation code }
On the second page, the code is counterchecked the content database. Depending on the check, either a failed attempt is counted or an error message is displayed and the previous page is repeated.
$code = strtolower(value('TC03')); // convert input to lower case $key = 'Code-'.$code; // add prefix for the database entry $data = dbGet($key); // reading the database entry // If no database entry is found if (!$data) { accessCount(600); // Create ban entry for 10 minutes and increment by one repeatPage('TC02'); // Show error message and repeat page }