", print_r($_POST, true), "
"; // show errors ini_set('display_errors',1); /* Read in CGI Data Let's begin by reading in all the data that are relevant to our project. Note: The simplist way to do this is to read in, quite literally, EVERYTHING that we will need at ANY point during the project--whether it exists at this pass or not. */ // Data the user gives us $v01 = $_POST['v01']; $v02 = $_POST['v02']; $v03 = $_POST['v03']; $v04 = $_POST['v04']; $v05 = $_POST['v05']; $myname = $_POST['myname']; // Some data that we create and want to use and read on each pass $pass = $_POST['pass']; // Where to start? // If pass is empty, assume it is the person's first time here // and set pass to 1 to start. if(empty($pass)){ $pass = 1; } /* Here are some arrays we could, theoretically, want access to at any stage of the game. Thus, let's initialize them here and do so fresh on each pass rather than passing them forward as hidden tags. (In general, if there is no need to pass data via hidden tags, then don't do it.) */ $item_content = array("tired","hungry","anxious","sad","excited"); // The content/items to be presented $item_names = array("v01","v02","v03","v04","v05"); // The variable names that will be associated with each item $number_of_items = count($item_names); // How many items/trials are there? $max_index = $number_of_items - 1; // Let's take 1 minus the above /* If pass == 1, then that signals to us that the user should receive whatever information we want to display on the FIRST VISIT (e.g., consent information, overview of study). */ // Pass = 1 if($pass == 1){ /* In addition to presenting a greeting on the first page(pass), we are also going to decide at this moment the random order in which the stimuli/items will be presented. We will do so by - creating an array that contains an index for each item (i.e., its place in the array file drawer). - shuffling/randomizing the order of that array - using that shuffled array to index the actual items (and their NAMEs) - Finally, we preserve that random order by passing it forward as hidden data */ $item_index = range(0,$max_index); print "The original index of items is
"; foreach ($item_index as $key => $value){ print "$key --> $value
"; } shuffle($item_index); print "The randomized index of items is
"; foreach ($item_index as $key => $value){ print "$key --> $value
"; } print "

Hello! Welcome to my website.

Please tell me your name.

"; /* Create HIDDEN tags for ALL information. Do this at start of FORM. */ print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print"

name

"; // The following shouldn't produce anything useful. Check HTML SOURCE to see if this is the case. print ""; /* These next lines of code are designed to pass arrays forward as hidden tags. This appears relatively complex. In short, we are going to loop through each element of the array. For each element, create a hidden tag with a common name (but with []) and the appropriate value. This looping solution is simply a shortcut way of writing out a separate hidden tag for each element of the array. Importantly, when PHP reads these hidden fields via the CGI data, it will appropriately read them into the named array. */ // Array of item_index (the randomized index values) foreach ($item_index as $key => $value){ echo ' '; print " \n"; } print "
"; } // End pass == 1 /* If pass>= 1 AND <= 7, then let's present the trials or items. Each time through, we increment pass by a value of 1. Thus, we end the "loop" once pass is 8 or higher. */ // We're going to skip the instructions this time, so setting $pass <= 6 instead of <= 7 if($pass >= 2 AND $pass <= 6){ print "
"; /* Create HIDDEN tags for ALL information. Do this at start of FORM. */ print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print "Do you currently feel...
"; // Array of item_index (the randomized index values) foreach ($item_index as $key => $value){ echo ' '; print " \n"; } $pass_index = $pass - 2; // let's count from 0 as we move through this section $this_item_content = $item_content[$item_index[$pass_index]]; // which item to present now? $this_item_name = $item_names[$item_index[$pass_index]]; // which item name to use? print "

$this_item_content

"; print ""; /* Here we are using a new trick. Specifically, instead of manually setting pass to the appropriate value (e.g., $pass=4;), we are going to increment it by 1. Thus, as the person moves from one item to the next, we increment pass by 1. This allows us to ensure that the person is getting the appropriate item at each step along the way. Notice also that, instead of writing $pass = $pass + 1, I wrote $nextpass = $pass + 1. I did this to ensure that I was not overwriting the current value of pass within the script. There are no ill consequenes of doing so here, but there are other situations in which it could matter. Thus, this is a generic solution to a problem that doesn't exist and, now, will never exist. */ $nextpass = $pass + 1; print ""; print "
"; } // End if($pass >= 2 OR $pass <= 6) // Pass = 8 /* We're at the end. Yay. */ if($pass == 7){ if($v01 == 1){ $message = "

Hope you're feeling more lively later today! Coffee helps.

"; } print "

Thanks for your time, $myname. $message

"; } // End pass == 8 ?>