[PHP][Tutorial] Basic Capcha
Well here it goes
PHP Code:
<? session_start(); ?>
<?php
$rawr = rand(100, 10000);
$_SESSION['rawr'] = $rawr ;
$capcha = $rawr;
?>
<? echo("$rawr"); ?><form method="post" action="rawr.php">
capcha: <input type="text" size="10" maxlenght="5" name="rawr">
<input="sumbit">
PHP Code:
<? session_start(); ?>
<?php
$capcha = $_POST['rawr'];
if ( $capcha == $rawr ) {
echo "Thank you, you may proceed";
} else {
echo "you /fail";
}
session_destroy();
?>
Rand = Random, it will randomize the numbers through the varibles ( 100-1000)
Ok so i have not used php in awhile so im not sure if i got all of the scripts
right. So please post with your responses to the tutorial.
re: [PHP][Tutorial] Basic Capcha
Don't captchas usually use pictures?
re: [PHP][Tutorial] Basic Capcha
Quote:
Originally Posted by
Cask
Don't captchas usually use pictures?
yes but this is a basic one. Or i would have used GD for the image, perhaps annother tutorial?
re: [PHP][Tutorial] Basic Capcha
I've tried to make one with images, just now, and I'm having a bit of trouble trying to match the codes:
Image.php
PHP Code:
<?php
// load PNG image
$image = imagecreatefrompng("http://forum.ragezone.com/images/captcha_background.png");
// load font
$font = "fonts/Tahoma.ttf";
// add code
/*$code = rand(10, 100);
$code = $code . " " . rand(10, 100);
$code = $code . " " . rand(10, 100);
$code = $code . " " . rand(10, 100);*/
$code = $_GET['code'];
imagefttext($image, 30, 0, 40, 57, null, $font, $code);
// show
header("Content-Type: image/png, html");
imagepng($image);
?>
Index.php (Form)
PHP Code:
<html>
<body>
<?php $image_text = rand(10, 100) . rand(10, 100) . rand(10, 100) . rand(10, 100);
if (isset($_POST['go']))
{
$input_code = $_POST['input_code'];
if ($input_code != $image_text)
{
echo 'You have entered an incorrect code, please try again.<br /><br />';
}
else
{
echo 'Congratulations, code successful!<br /><br />';
}
}
?>
<img src="image.php?code=<?php echo $image_text; ?>">
<FORM METHOD="POST">
<table>
<tr>
<td>
Type in the code from the above image:
</td>
</tr>
<tr>
<td>
<input type="text" name="input_code">
</td>
</tr>
<tr>
<td>
<input type="submit" name="go">
</td>
</tr>
</table>
</FORM>
</body>
</html>
re: [PHP][Tutorial] Basic Capcha
Cask, you should try use a session to store the captcha data. Create the session in the image script and you can check the result in any of your other scripts.
1 Attachment(s)
re: [PHP][Tutorial] Basic Capcha
Quote:
Originally Posted by
greenowl
Cask, you should try use a session to store the captcha data. Create the session in the image script and you can check the result in any of your other scripts.
Ah yes, thankyou, I'll try it after I have a flog, bbs.
Edit, well that was quick, good porn.
-
Thanks Greenowl, your idea works.
Script attatched.
Includes:
- index.php
- image.php
- images/captcha_background.png
- fonts/Tahoma.ttf
Re: [PHP][Tutorial] Basic Capcha
Call to undefined function imagecreatefrompng()
Re: [PHP][Tutorial] Basic Capcha
Quote:
Originally Posted by
eele
Call to undefined function imagecreatefrompng()
You may have to update your PHP, or if you have PHP 6.0.0, some of those functions may not work as it is GD1, it has since been upgraded to GD2.
http://au.php.net/manual/en/image.setup.php
Re: [PHP][Tutorial] Basic Capcha
Quote:
Originally Posted by
Cask
Thnx.