Jump to content
Aerosol

Create a Captcha images & form

Recommended Posts

Doar copiezi si apoi adaugi in

public_html

index.php


<?php
session_start();

if ( isset( $_POST['submit'] ) )
{
$code = strip_tags( $_POST['code'] );
$real_code = $_SESSION['captcha_code'];
if ( $code !== $real_code )
{
echo "Wrong code! Code was {$real_code}";
}
else
{
echo "Correct code!";
}
}
else
{
?>
<form method="post">
<img src="captcha.php" /><br />
Enter code: <input type="text" name="code" /> <input type="submit" name="submit" value="Go" />
</form>
<?php
}
?>

captcha.php


<?php
/* This tutorial will teach you how to create your own Captcha image. */

session_start();
$chars = "1234567890qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM";
$length = ( isset( $_GET['l'] ) && is_numeric( $_GET['l'] ) ) ? (int)$_GET['l'] : 8;

$captcha = "";
for ( $i = 1; $i <= $length; $i++ )
{
$captcha .= $chars[ mt_rand( 0, strlen( $chars ) ) ];
}

$_SESSION['captcha_code'] = $captcha;

$width = ( $length * 10 ) - 3;
$img = imagecreate( $width, 17 );
$bg = imagecolorallocate( $img, 0, 0, 0 ); //black
$txt = imagecolorallocate( $img, 255, 255, 255 ); //white
imagestring( $img, 5, 3, 1, $captcha, $txt );

header( "Content-Type: image/PNG" );
imagepng( $img );
imagedestroy( $img );
?>

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...