v0.0.4
This commit is contained in:
50
irpg-web/captchaimage.php
Normal file
50
irpg-web/captchaimage.php
Normal file
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
session_start();
|
||||
|
||||
// Create a blank image
|
||||
$width = 52;
|
||||
$height = 16;
|
||||
$image = imagecreate($width, $height);
|
||||
$backgroundColor = imagecolorallocate($image, 212, 255, 226);
|
||||
imagefilledrectangle($image, 0, 0, $width, $height, $backgroundColor);
|
||||
|
||||
// Add some text
|
||||
$captchaString = "";
|
||||
$allowedChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
||||
$charColor = imagecolorallocate($image, 64, 64, 64);
|
||||
$numChars = 5;
|
||||
for ($i=0; $i<$numChars; $i++)
|
||||
{
|
||||
$char = $allowedChars[rand(0, strlen($allowedChars)-1)];
|
||||
imagestring($image, 5, 2+($i*10), 0, $char, $charColor);
|
||||
$captchaString .= $char;
|
||||
}
|
||||
|
||||
// Save the text to a session variable.
|
||||
$_SESSION['captchaString'] = $captchaString;
|
||||
|
||||
// Add some lines
|
||||
$lineColor = imagecolorallocate($image, 234, 132, 13);
|
||||
$numLines = rand(2,2);
|
||||
for($i=0; $i<$numLines; $i++)
|
||||
{
|
||||
imageline($image, 0, rand()%16, 52, rand()%16, $lineColor);
|
||||
}
|
||||
|
||||
// Add some pixels
|
||||
$pixelColor = imagecolorallocate($image, 11, 213, 142);
|
||||
$numPixels = rand(38,40);
|
||||
for($i=0; $i<$numPixels; $i++)
|
||||
{
|
||||
imagesetpixel($image, rand()%52, rand()%16, $pixelColor);
|
||||
}
|
||||
|
||||
// Set the content type header - in this case image/jpeg
|
||||
header('Content-type: image/jpeg');
|
||||
|
||||
// Output the image
|
||||
imagejpeg($image);
|
||||
|
||||
// Free up memory
|
||||
imagedestroy($image);
|
||||
?>
|
||||
Reference in New Issue
Block a user