Common Code
PHP Code Examples
[Download]
<?php

// Survey file location.
$surv_loc = '/home/bennet/phpwrite/surveys';

// Map from the $PATH_INFO value to the actual file name.  Also checks that
// the name is legal and dies if not.
function get_fn($which, $pi) {
	if(!preg_match('/^[A-Za-z0-9_]+$/', $pi))
		// Surveyname contains bad characters.
		whap('Illegal Survey Name',
		     "The given survey name $pi is not legal.");

	global $surv_loc;
	return "$surv_loc/${which}_$pi";
}

// Open the survey file and die whining on failure.  Otherwise return
// the file handle.
function open_sur($pi) {
	$surfile = get_fn('sur', $pi);
	$surdef = @fopen($surfile, 'r');
	if(!$surdef) whap('No Such Survey',
			  "The survey designated by $pi was not found ".
			  "on this server.");

	return $surdef;
}
?>