Skip to content

Basic online Attentional Bias Modification experiment in Javascript and PHP


Notifications You must be signed in to change notification settings


Folders and files

Last commit message
Last commit date

Latest commit



18 Commits

Repository files navigation


This is an example of a basic online Attentional Bias Modification (ABM) experiment using Javascript and PHP. The experiment consists of a pre-training assessment, four daily training sessions, a post-training assessment, and follow-up after one week.

To use it, you need to upload the unzipped directory to your website. I suggest getting hosting from Dreamhost - everything works with them (this isn't necessarily the case for all hosting providers, especially concerning PHP functions). You will need a GMail account set up to automatically forward mails. You will also need a running cron job for emailing session-invitations, adjusted from the lines below:


curl ""

The php script taskParams.php contains parameters you need to set up for the software to work on your system or to adjust the experiment. For instance, you will need to use the correct directory address and log-in details for your GMail.

Once the files are uploaded, participants can follow a link to register. This would look soemthing like:

Replace the username "666" with the correct one. The login-source, loginsrc, can be set to Sona1 or Sona2 if you're integrating the experiment in Sona systems. The participant will be sent to an Information and Informed Consent screen where they can choose whether to participate and if so, fill in their email address and a time of day to receive invitations.

The first invitation will be sent immediately after registering. Most other invitations are sent one day after completing the previous session. The final invitation is sent after seven days. An email is sent to the researcher-email address when a session is completed.

The /Online directory contains the PHP functions. To understand the code, start with register.php and just follow the links, and when you test the experiment note the PHP pages you're sent to.

The /Online/jsfiles directory contain directories with Javascript for questionnaires and tasks. Both questionnaires and tasks are controlled by a Manager (questionnaireManagerObj.js and generalTaskMachine.js) function, which interfaces with the webpage and presents specific questionnaires and tasks in order.

Tasks are organized as an abstract task object (abstractTask.js), which is a general template containing all the boilerplate for presenting blocks and trials. The abstract task is adjusted via an adapt-function to become a particular task. In this experiment, this is a Dot-Probe task, created in taskDP_general.js. Parameters provided to the adapt-function allow for variations on the task. In this case, a Baseline, Assessment and Training version of the Dot-Probe are created, in taskDP_versions.js. Tasks are used in tasks.php and train.php.

Questionnaires are based on template questionnaire (templateQ.jsand templateQPic.js) that is adjusted via a function to create a particular questionnaire. See adhocQ.js in Q_EN for an example. The PHP file Q.php loads the necessary files.

The /Online/Stims directory contains subdirectories with pictures used for assessment and training. These can be changed as desired as long as the filenames remain the same, i.e., stim (1).jpg (and of course the number of stimuli must be sufficient for the task; the provided Dot-Probe task needs 20 pictures per stimulus category). There are also stimulus directories here used for the FACE self-reported emotional reactivity questionnaire (Gladwin, 2017, Health Psychology and Behavioral Medicine).

Data are saved to the /Online/results directory. The data are saved as JSON strings, one line per questionnaire or trial.

You need to have SwiftMailer ( installed under Common/swiftmailer-5.x in the root directory of your website. To change the SwiftMailer directory, adjust the references in mailsender.php and register2.php.

Please cite as: Thomas Edward Gladwin. (2017, August 16). thomasgladwin/onlineABM: Basic online ABM. Zenodo.