giuliomoro@0: 0; $i--)
giuliomoro@0: {
giuliomoro@0: $j = @mt_rand(0, $i);
giuliomoro@0: $tmp = $items[$i];
giuliomoro@0: $items[$i] = $items[$j];
giuliomoro@0: $items[$j] = $tmp;
giuliomoro@0: }
giuliomoro@0: }
giuliomoro@0: function url_origin( $s, $use_forwarded_host = false ) //http://stackoverflow.com/questions/6768793/get-the-full-url-in-php
giuliomoro@0: {
giuliomoro@0: $ssl = ( ! empty( $s['HTTPS'] ) && $s['HTTPS'] == 'on' );
giuliomoro@0: $sp = strtolower( $s['SERVER_PROTOCOL'] );
giuliomoro@0: $protocol = substr( $sp, 0, strpos( $sp, '/' ) ) . ( ( $ssl ) ? 's' : '' );
giuliomoro@0: $port = $s['SERVER_PORT'];
giuliomoro@0: $port = ( ( ! $ssl && $port=='80' ) || ( $ssl && $port=='443' ) ) ? '' : ':'.$port;
giuliomoro@0: $host = ( $use_forwarded_host && isset( $s['HTTP_X_FORWARDED_HOST'] ) ) ? $s['HTTP_X_FORWARDED_HOST'] : ( isset( $s['HTTP_HOST'] ) ? $s['HTTP_HOST'] : null );
giuliomoro@0: $host = isset( $host ) ? $host : $s['SERVER_NAME'] . $port;
giuliomoro@0: return $protocol . '://' . $host;
giuliomoro@0: }
giuliomoro@0:
giuliomoro@0: function full_url( $s, $use_forwarded_host = false )
giuliomoro@0: {
giuliomoro@0: return url_origin( $s, $use_forwarded_host ) . $s['REQUEST_URI'];
giuliomoro@0: }
giuliomoro@0: $toAppendToUrl = '';
giuliomoro@0: if(isset($_GET["id"])){
giuliomoro@0: $id = $_GET["id"];
giuliomoro@0: } else {
giuliomoro@0: $max = pow(2, 24);
giuliomoro@0: $rand = openssl_random_pseudo_bytes($max);
giuliomoro@0: $id = sha1($rand);
giuliomoro@0: if(sizeof($_GET) == 0){ // if the query string is empty
giuliomoro@0: $toAppendToUrl = '?'; // start the query string
giuliomoro@0: } else {
giuliomoro@0: $toAppendToUrl = '&'; // otherwise, append to it
giuliomoro@0: }
giuliomoro@0: $toAppendToUrl .= 'id='.$id;
giuliomoro@0: }
giuliomoro@0: if(isset($_GET["next"])){
giuliomoro@0: $next = $_GET["next"];
giuliomoro@0: } else {
giuliomoro@0: $next = 0;
giuliomoro@0: }
giuliomoro@0:
giuliomoro@0: $absoluteUrl = full_url($_SERVER).$toAppendToUrl;
giuliomoro@0: // echo "
".$absoluteUrl."
";
giuliomoro@0: // if there is a "next" in the query string, create a version of $absoluteUrl with
giuliomoro@0: // next:=next+1
giuliomoro@0: $absoluteUrlSplit = explode('?', $absoluteUrl);
giuliomoro@0: $absoluteUrlNextPlusOne = $absoluteUrl;
giuliomoro@0: if(sizeof($absoluteUrlSplit) === 2){
giuliomoro@0: $queryString = $absoluteUrlSplit[1];
giuliomoro@0: parse_str($queryString, $queryStringParsed);
giuliomoro@0: $queryStringParsed['next'] += 1;
giuliomoro@0: $queryString = http_build_query($queryStringParsed);
giuliomoro@0: $absoluteUrlNextPlusOne = $absoluteUrlSplit[0]."?".$queryString;
giuliomoro@0: }
giuliomoro@0: $defaultTestEntry = Array('url' => null, 'string' => null, 'class' => 'disabled', 'a' => false, 'editable' => false);
giuliomoro@0:
giuliomoro@0: require_once('test_list.php'); //this returns $tests
giuliomoro@0:
giuliomoro@0: if($next == sizeof($tests)){
giuliomoro@0: // we are done
giuliomoro@0: $bottomBox = 'The test is complete, thank you for your participation.';
giuliomoro@0: } else {
giuliomoro@0: $bottomBox = 'If you want to have a break, come back to this page and continue from where you left, just come back to this URL: