Navigation stuff goes here


Concept: Moving an experiment to the web

I recommend that you do not tackle this without the aid of someone who understands web servers.

What can be moved to the web

Once you have your experiment working on your own computer you may want to move some part of it to the web. There are two parts of it that can be moved, and they can be moved independently: you can move one to the web and leave the other, or move them both.

  1. Putting the script and stimuli on a web server so you can run the experiment on any computer
  2. Collecting results using a web server so all results are sent to one computer no matter where the experiment is run

Putting your script and stimuli on a web server means you, or other people can run the experiment on any computer/device with a working web browser. PsyScript experiments will even work on small devices like a smartphone, with a few restrictions due to things that such devices cannot or will not do for security reasons.

Collecting results using a web server means that instead of the log of a session being held inside the device the experiment was run on, the log is sent to a web server. A program running on the web server can then store that log away in a text file ready for you or someone else to read. All results from everyone running that experiment can be stored in one big log file, ready for import into Excel or SPSS whenver you want. It is not possible for someone running the experiment to figure out the log file's location just by looking at the files involved in the experiment. You can keep that a secret.

The move I've described first is the simpler of the two, and it provides some testing for the one I describe second.

Prerequisites for doing either of the above

  1. You will need a working web server which can serve static files over HTTP or HTTPS, whichever you want to use. You can run this yourself or have access to one that someone else runs.
  2. You'll need the privilages necessary to upload, replace and delete pages on this server. It is acceptable to have this not for the whole server but for just some part of its service space or to just the space used by one port.
  3. You'll need whatever software is necessary to upload, replace and delete pages on this server. This changes with the type of server and how that server is set up, so don't ask for my help with it: it's done with whatever software you have, not PsyScript.

You think you have all the above ? Test it before continuing. Make sure you know how to do those things. Copy a new page onto your web server and make sure people can see it in their web browsers.

Additional prerequisite for collecting results using a web server

I recommend that you do not tackle this without the aid of someone who understands how to run a web-facing application on a web server.

In order to collect results using a web server you need to be able to not just put static pages on a web server but also to be able to run programs on your web server.

I've provided a working example of such a program – saveALog.php – written in PHP, the most well known server-side programming language. This program is available for download, and an example is running on our own server for your use for testing purposes.

If your web server can run PHP programs (the most commonly used ones can) then you can use my example just as it is or modify it to work the way you want. My own example runs on both the most up-to-date and also some old versions of PHP.

You can also replace my program entirely with another written in PHP or any other language your web server supports. This documentation explains the protocol used.


Putting the script and stimuli on a web server

Once you have your experiment working on your computer you have a folder with the script and some stimuli in it. Putting that material on your web server involves a few steps.

Warning: For steps 1 and 2 don't put one of those folders inside the other. This can create access problems later. You can create one folder and put both folders inside that one if you like.

  1. copy the 'PsyScript3/editor' folder with all its contents onto the server. You can change the name from 'editor' to something else if you want.
  2. copy your experiment folder with all its contents onto the server
  3. open the 'whatsMyPath.html' file from the web server copy of your experiment folder in your browser making sure you're accessing it with HTTP or HTTPS and not as a file:// URL.
  4. check to see that it says the path is suitable for running your experiment on the web
  5. take a copy of your experiment script file and put it in the 'editor' folder with the name 'experiment.txt'.
  6. In that copy, replace the 'define homeFolder' line with the one shown by the 'whatsMyPath.html' web page you opened earlier

Once you've done this, pointing a browser at the 'experiment.html' file in the 'editor' folder will allow your participants to run an experiment in their browser.

The online experiment program looks for three textblocks with special names in your experiment script: 'Title', 'Brief' and 'Debrief', and shows these at appropriate times before and after running the experiment. You might want to put dummy text in these blocks to see how they work, then correct the text to something more appropriate.


Collecting your session logs on a web server

Collection of the session log is controlled by the define logMethod line in your script. Normally this will read

    define logMethod localStorage

which tells psyScript to supply logs to whatever browser you're running. However you can instead define the logMethod to be something like

    define logMethod [URL] [key]

for example

    define logMethod https://open.psych.lancs.ac.uk/software/PsyScript3/saveALog.php test2

The URL is the URL of a web page to send the log to. The key is a string you can send to that web page with your log. It can be used to tell that web page how to file the log. For example, to tell the web page which experiment the log was generated by, or which participant pool of subjects your participant was from. PsyScript sends the key and log as object properties 'theDestKey' and 'theLog' in JSON-formatted POST data which looks like the following:

    {"theDestKey": "test2",
         "theLog": "\tthis is the first logged item\tthis is the second logged item",
        "thePath": "https://open.psych.lancs.ac.uk/software/PsyScript3/projects/test%20scripts/"}

An example PHP application called saveALog.php is available and can be downloaded from the PsyScript homepage. It accepts the POST data and writes the log away to a file on disk indicated by the 'theDestKey' parameter. This PHP application uses the 'key' supplied to specify a file on disk to append the new log information to.

Security

You may want to make sure that the contents of the experiment log is kept private. If you use HTTPS in your logMethod URL (as is used in the above example), then the data will be sent from the experiment device to the server in an encrypted form. You can, of course, only do this is the server you're using supports HTTPS and has an appropriate certificate. If you don't understand these issues, consult someone who is familiar with web server technology.


See also