Sending Data to a Server

The following examples run a simple response time measurement 'experiment' with three trials.

The file srt_GET_mailer.pxd sends the data to a short PHP script which mails them to a destination address. This demonstration uses the HTTP GET method and the browser's server connection to send the data. Note that in this case a response window pops up and provides some feedback about the data having been sent. Also note that sending data with GET only works for applets since the server connection is managed by the browser in this case.

The file srt_POST_mailer.pxd sends the data to the same PHP script which mails them to a destination address. This example uses the HTTP POST method. In this case PXLab creates its own serever connection to send the data. This is hidden from the browser and also works for applications.

The design file srt.pxd does not contain any special information about where to send the data. If this design file is run by a PXLab application program then the data are stored in a data file in the current working directory. If the same file is run as an applet then a new browser window pops up after the experiment and shows the resulting data file. Note that the browser needs to have pop up windows enabled for this to work. Also, the HEAD section of the HTML file must contain the following JavaScript code and JavaScript has to be enabled:

<SCRIPT>
function showData(s) {
ergWin = window.open()
ergWin.document.write(s)
}
</SCRIPT>

 

Receiving and Mailing Data with PHP

The examples which send the data to an E-Mail address use a PHP-script on the server to receive the data from PXLab and send them to an E-Mail address. This is achieved by setting the following parameters in the respective design file:
Experiment(DataFileDestinationAddress) {
  Context() {
    AssignmentGroup() {
      ...
      DataFileDestination = "/pxlab/demos/mailer.php";
      DataFileDestinationAddress = "";
      HTTPRequestMethod = "POST";
      ...

The main point here is the value of DataFileDestination. PXLab recognizes that this is a valid URL and thus uses this target for the data file. If the value of DataFileDestination is the name of a directory in the local file system then the data are stored there.

The argument of the Experiment() node asks the user for the destination E-Mail address. Instead of asking the user the DataFileDestinationAddress could also be set in the design file. The receiving script is contained in file mailer.php. The scripting language PHP makes it very simple to receive the data:

<?php
$SendData = "\nSending Document: ".$_SERVER['HTTP_REFERER']."\n".
"Source IP: ".$_SERVER['REMOTE_ADDR']."\n".
"Script: ".$_SERVER['SCRIPT_FILENAME']."\n".
"Request Method: ".$_SERVER['REQUEST_METHOD']."\n".
"Email: ".$_REQUEST['Email']."\n".
"DataFileName: ".$_REQUEST['DataFileName']."\n".
"Data: \n\n".$_REQUEST['Data']."\n";

mail($_REQUEST['Email'], "PXLab Data File ".$_REQUEST['DataFileName'], $SendData, "From: PXLab" );
?>

The PXLab data file <?php echo $_REQUEST['DataFileName']; ?> has been sent to <?php echo $_REQUEST['Email']; ?>.

Sending Data to a Data Base

The following example runs a simple response time measurement 'experiment' with three trials. The design file srt_dbase.pxd sends the data to a PHP script which enters the data into a data base. The first button below uses the HTTP GET method to send its data to the server. This has the advantage that the server will generate a response page which will be shown by the browser.

This design file will ask you for a subject code. Please enter a code which you expect to be unique. Otherwise the data base server will not accept the data.

The next button runs the same experiment but uses the HTTP POST method to send its data. This should always be used since the GET method can only send a limited amount of information. The POST method does not have that limitation. The disadvantage of the POST method is that it surpasses the browser and thus the server's response will not be shown by the browser. The PXLab applet prints the server's response into the console window. Thus if you want to see the server's response you may open the JRE console window of the browser and there is the server's response.

This design file will ask you for a subject code. Please enter a code which you expect to be unique. Otherwise the data base server will not accept the data.

If your experiment has run successfully and the POST request has been satisfied you may open the Java runtime environment console window and see the server's response.

You may download an archived sample PHP script which receives the data, parses the data into trials and stores the trials into a data base.


© H. Irtel, 2007.