PHP gevorderde |
|
<?php
session_start();
if ($_SERVER['REQUEST_METHOD'] == 'POST')
{
if (isset($_POST['captcha']) && $_POST['captcha'] == $_SESSION['captcha'])
{
echo 'De ingevulde code komt overeen met de captcha.';
}
else
{
echo 'De ingevulde code komt niet overeen met de captcha.';
}
}
else
{
$_SESSION['captcha'] = 'ax84D'; // dit is een voorbeeld, normaal genereert men dit.
}
?>
<form id="captchaform" method="post" action="">
<div>
<img src="captcha.php" alt="De captcha code." /><br />
<label for="captcha">Captcha</label>
<input id="captcha" name="captcha" type="text" /><br />
<input id="submit" name="submit" type="submit" value="Controleer" />
</div>
</form>
<?php if ($_SERVER['REQUEST_METHOD'] == 'POST') { if (isset($_POST['captcha']) && $_POST['captcha'] == $_SESSION['captcha']) { echo 'De ingevulde code komt overeen met de captcha.'; } else { echo 'De ingevulde code komt niet overeen met de captcha.'; } } else { $_SESSION['captcha'] = 'ax84D'; // dit is een voorbeeld, normaal genereert men dit. } ?> <form id="captchaform" method="post" action=""> <div> <img src="captcha.php" alt="De captcha code." /><br /> <label for="captcha">Captcha</label> <input id="captcha" name="captcha" type="text" /><br /> <input id="submit" name="submit" type="submit" value="Controleer" /> </div> </form>
<?php
session_start();
$captcha = $_SESSION['captcha'];
$length = strlen($captcha);
$background = array('images/blue.png', 'images/red.png', 'images/green.png', 'images/yellow.png');
$image = imagecreatefrompng($background[rand(0, 3)]);
$colour = imagecolorallocate($image, 255, 255, 255);
$font = array('font/arial.ttf', 'font/CALIBRI.TTF', 'font/tahoma.ttf', 'font/ARIALN.TTF', 'font/CORBELI.TTF');
if ($length == 4)
{
$pos[0] = rand(45,50);
$pos[1] = rand(65,70);
$pos[2] = rand(80,91);
$pos[3] = rand(105,127);
}
elseif ($length == 5)
{
$pos[0] = rand(45,50);
$pos[1] = rand(65,70);
$pos[2] = rand(80,91);
$pos[3] = rand(105,127);
$pos[4] = rand(130,152);
}
for($i = 0; $i < $length; $i++)
{
imagettftext($image, rand(12,23), rand(-45,45), $pos[$i], 32, $colour, $font[rand(0,4)], $captcha[$i]);
}
header('content-type: image/png');
imagepng($image);
imagedestroy($image);
?>
<?php $captcha = $_SESSION['captcha']; $background = array('images/blue.png', 'images/red.png', 'images/green.png', 'images/yellow.png'); $image = imagecreatefrompng ($background[rand(0, 3)]); $colour = imagecolorallocate($image, 255, 255, 255); $font = array('font/arial.ttf', 'font/CALIBRI.TTF', 'font/tahoma.ttf', 'font/ARIALN.TTF', 'font/CORBELI.TTF'); if ($length == 4) { } elseif ($length == 5) { } for($i = 0; $i < $length; $i++) { imagettftext ($image, rand(12,23), rand(-45,45), $pos[$i], 32, $colour, $font[rand(0,4)], $captcha[$i]); } header('content-type: image/png'); imagepng($image); imagedestroy($image); ?>
|