<?php
/* 
 * Turning Redirector
 *
 * Copyright (c) 2004 Colin Viebrock <colin@viebrock.ca>
 * 
 * Usage of the works is permitted provided that this
 * instrument is retained with the works, so that any entity
 * that uses the works is notified of this instrument.
 * 
 * DISCLAIMER: THE WORKS ARE WITHOUT WARRANTY.
 */

session_start();

$num_guesses 3;

if ( 
$_SERVER['REQUEST_METHOD'] == 'POST' ) {

    if ( 
strtolower($_SESSION['turing_string']) == strtolower($_POST['guess']) ) {
        unset(
$_SESSION['turing_guesses']);
        
$_SESSION['turing_pass'] = true;
        
Header('Location: ' $_SESSION['turing_redirect'] );
        exit;

    }

    if (++
$_SESSION['turing_guesses'] >= $num_guesses ) {

        
pageHeader();
        echo 
'<h1>Denied</h1>';
        echo 
'<p>You made too many wrong guesses.  Sorry.</p>';
        
pageFooter();
        exit;

    }

    
$msg '<p class="error">' .
        
'You got it wrong.  You have ' 
        (
$num_guesses $_SESSION['turing_guesses']) .
        
' more attempt(s) to get it right.' .
        
'</p>';
}

$action $_SERVER['PHP_SELF'];

pageheader();

echo <<< EOB

<h1>Turing Protection</h1>

<p>
In order to follow the link you clicked, we ask that you pass a simple test.
</p>

<p>
This test designed to foil automatic webpage-trolling systems; only humans
should be able to (easily) get past this test.
</p>

{$msg}

<p>
Enter the string of characters you see in the image on the left into the 
text field on the right and click "continue".  If you get it right, you 
will be redirected to the page you originally requested.  If you get it 
wrong, you will get another chance.
</p>

<form method="post" action="
{$action}">

<table border="0">
<tr valign="middle">
<td>
<img src="/site-images/turing-image.php" />
</td>
<td>
<input type="text" size="20" name="guess" />
<input type="submit" value="Continue" />
</td>
</tr>
</table>

</form>

<p>
If you are visually impared, and can not read the above image, you can
<a href="/site-images/turing-sound.php" target="_blank">click here</a>.  This will open
a .WAV file in a new browser window.  The .WAV file contains the string of 
characters read out loud via a speech synthesis program.<sup>1</sup>  You can then
come back to this browser window and enter the string.
</p>

<p>
You can also <a href="javascript:history.back();">go back a page</a>.
</p>

<hr noshade="noshade">

<p><small>
<sup>1</sup> This is still a bit experimental, so our apologies if it doesn't work very well.
</small></p>

EOB;

pageFooter();
exit;






function 
pageHeader() {
echo <<< EOB
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
    <meta http-equiv="content-type" content="text/html; charset=utf-8" />
    <link rel="stylesheet" href="/css.php?s=default" type="text/css" />
    <title>Turing Protection</title>
</head>
<body>
<div id="container" class="turing">
<div id="center">
EOB;
}

function 
pageFooter() {
    echo <<< EOB
</div>
</div>
</body>
</html>
EOB;
}