note 94975 deleted from function.imagettftext by cmb
| From: | cmb@php.net | Date: | Sun, 28 Jul 2019 08:12:42 +0000 |
| Subject: | note 94975 deleted from function.imagettftext by cmb | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-211727@lists.php.net to get a copy of this message | ||
Note Submitter: adam at worldwrestlingmania dot cjb dot net
----
Here's a good number verification captcha i just made:
1. on the page/s it will be used on, enter:
<?php
$pageToGo = "http://example.com/" #the page to go
to if captcha correct
if ($_POST["captchaused"] == "true")
{
if ($_POST["numcaptcha"] == $_POST["captcha"])
{
header('Location: ' . $pageToGo);
}
else
{
echo '<form action="' . $_SERVER['php_self'] . '"
method="post">';
$text = mt_rand();
echo '<input type="hidden" name="captchaused" value="true"
/>';
echo '<input type="hidden" name="numcaptcha" value="' . $text
. '" />';
echo 'Enter the numbers you see: <br><input type="text"
name="captcha" />';
require_once('numcaptcha.php');
echo '<input type="submit" value="enter site" /></form>';
}
?>
2. create a page called numcaptcha.php and enter:
<?php
header('Content-type: image/png');
$im = imagecreatetruecolor(400, 30);
$white = imagecolorallocate($im, 255, 255, 255);
$grey = imagecolorallocate($im, 128, 128, 128);
$black = imagecolorallocate($im, 0, 0, 0);
imagefilledrectangle($im, 0, 0, 399, 29, $white);
imagettftext($im, 20, 0, 11, 21, $grey, $font, $text);
imagettftext($im, 20, 0, 10, 20, $black, $font, $text);
imagepng($im);
imagedestroy($im);
?>
it might have a few security issues but it still works fine.