Everything in this tutorial is being used on my faucet. Check it out
HERE to see it in action!
Step FourIn step four we will be adding a simple math question displayed as an image as a second captcha. Faucet users cannot claim their satoshi until the math question is solved.
Download PHP captcha
HERE extract it and add the "captcha" folder to your root directory. If you don't trust that download you can find the original
HERE, it will require some configuring though.
Now open your template file (ROOTDIRECTORY/faucet/templates/YOURTEMPLATE/index.php) paste the following code at the very top line above <!DOCTYPE html>:
<?php session_start(); ?>
Paste the following code where you would like the equation to appear
<img id="captcha" src="/captcha/securimage_show.php" alt="CAPTCHA Image" />
<br>
<a href="#" onclick="document.getElementById('captcha').src = '/captcha/securimage_show.php?' + Math.random(); return false">[ New Problem ]</a>
<br>
<br>
<input type="text" name="captcha_code" size="10" maxlength="6" />
<br>
<br>
Now you need to create a PHP document. I use a program called Notepad++, however any text editor will work. Create a new document, then paste in the following code:
<?php>
include_once $_SERVER['DOCUMENT_ROOT'] . '/captcha/securimage.php';
$securimage = new Securimage();
if ($securimage->check($_POST['captcha_code']) == false) {
// the code was incorrect
// you should handle the error so that the form processor doesn't continue
// or you can use the following code if there is no validation or you do not know how
echo "I'm sorry but you have to answer the math question correctly!.<br /><br />";
echo "Please go <a href='javascript:history.go(-1)'>back</a> and use a caculator.";
exit;
}
?>
Keep the document open. Open your faucet index page, it will most likely be index.php in your ROOTDIRECTORY. (Not the template index.php) Now press CTRL+A and select everything and copy it. Go back to the document you were just making and paste it on the very bottom, underneath the ?> Now save the file as what ever you want, I called mine math.php.Go back to your faucet template file (ROOTDIRECTORY/faucet/templates/YOURTEMPLATE/index.php) search for the following:
<form method="POST" class="form-horizontal" role="form">on that same line link your PHP file to it like so:
<form action="math.php" method="POST" class="form-horizontal" role="form">
About the Step 4... Why don't you just use:include_once $_SERVER['DOCUMENT_ROOT'] . '/faucet/index.php';
Instead of
select everything, copy it, go back to the document you were just making and paste it on the very bottom?And there is a Problem!After using this math script, the referral link become:
--
http://yoursite.com/faucet/math.php?r=1XX9xXXZ3XTXXX5kTXxXKCvxkiXNXxdGXNInstead of:
--
http://yoursite.com/faucet/?r=1XX9xXXZ3XTXXX5kTXxXKCvxkiXNXxdGXNHow to fix it?