$value){ if(!empty($value)){ $sum = $sum + $value; $n = $n + 1; } } $average = "Error. There were not enough cases to compute an average."; if($n > 0){ $average = $sum/$n; $average = round($average,2); } return $average; } /* ------------------------------------------ If the user is logged in, he or she will have a cookie on his or her machine. If no cookie exists, redirect the user to login page. ------------------------------------------ */ if(!isset($_COOKIE['user_id']) OR !isset($_COOKIE['sessionID']) OR !isset($_COOKIE['first_name']) ){ redirect_user(); exit(); } // show errors ini_set('display_errors',1); // Read in user-submitted CGI data $v01 = $_POST['v01']; $v02 = $_POST['v02']; $v03 = $_POST['v03']; $v04 = $_POST['v04']; $v05 = $_POST['v05']; $v06 = $_POST['v06']; // Read in programmer-generated data $pass = $_POST['pass']; // Where to start? if(empty($pass)){ $pass = 1; } /* We store the item content and the variable names in arrays. Doing so allows us to easily access the content-variable_name pairs independently of the order in which the items appear. In fact, we randomize the order of the items later. */ $item_content = array("It helps to turn to this person in times of need.","I usually discuss my problems and concerns with this person.","I find it easy to depend on this person.","I often worry that this person doesn't really care for me.","I'm afraid that this person may abandon me.","I worry that this person won't care about me as much as I care about him or her."); $item_names = array("v01","v02","v03","v04","v05","v06"); // 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 because PHP starts counting array elements at 0 // Include external style sheet print "
"; // Pass = 1 if($pass == 1){ // Determine the randomized order of items $item_index = range(0,$max_index); shuffle($item_index); // Pull out user's first name form cookie. $fn = $_COOKIE['first_name']; print "";
print "
Hello, $fn. Please answer the following questions about your dating or marital partner. Note: If you are not currently in a dating or marital relationship with someone, answer these questions with respect to a former partner or a relationship that you would like to have with someone. "; print " |