Help!
| From: | David Summers | Date: | Wed, 19 Nov 2014 21:57:25 +0000 |
| Subject: | Help! | ||
| Groups: | php.webmaster | ||
| Request: | Send a blank email to php-webmaster+get-20285@lists.php.net to get a copy of this message | ||
Hello,
I was hoping to get in touch with someone on a situation that I cannot find
the solution to anywhere.
I am trying to create a captcha on my website using php and although I was
able to create an image shown here
https://www.gcus.com/deletemeafter/captcha/security_image.php
and create the random captcha text here:
https://www.gcus.com/deletemeafter/captcha/testerPHP.php
I am unable to over lay the two. Here is my code:
<?PHP
session_start();
function generateRandomString($length = 10) {
$letters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
$len = strlen($letters);
$letter = $letters[rand(0, $len - 1)];
$text_color = imagecolorallocate($image, 0, 0, 0);
$word = "";
for ($i = 0; $i < 6; $i++) {
$letter = $letters[rand(0, $len - 1)];
imagestring($image, 7, 5 + ($i * 30), 20, $letter, $text_color);
$word .= $letter;
}
$_SESSION['captcha_string'] = $word;
}
function security_image(){
// $code = isset($_SESSION['captcha']) ? $_SESSION['captcha'] :
generate_code();
//$font = 'content/fonts/comic.ttf';
$width = '110';
$height = '20';
$font_size = $height * 0.75;
// $image = @imagecreate($width, $height) or die('GD not installed');
global $image;
$image = imagecreatetruecolor($width, $height) or die("Cannot Initialize
new GD image stream");
$background_color = imagecolorallocate($image, 255, 255,
255);
imagefilledrectangle($image,0,0,200,50,$background_color);
$line_color = imagecolorallocate($image, 64,64,64);
for($i=0;$i<10;$i++) {
imageline($image,0,rand()%50,200,rand()%50,$line_color);
}
$pixel_color = imagecolorallocate($image, 0,0,255);
for($i=0;$i<1000;$i++) {
imagesetpixel($image,rand()%200,rand()%50,$pixel_color);
}
//$textbox = imagettfbbox($font_size, 0, $font, $code);
//$textbox = imagettfbbox($font_size, 0, $randomString);
$x = ($width - $textbox[4]) / 2;
$y = ($height - $textbox[5]) / 2;
// imagettftext($image, $font_size, 0, $x, $y, $text_color, $font ,
$code);
//imagettftext($image, $font_size, 0, $x, $y, $text_color , $word);
$images = glob("*.png");
foreach ($images as $image_to_delete) {
@unlink($image_to_delete);
}
imagepng($image, "image" . $_SESSION['count'] . ".png");
header('Content-Type: image/png');
imagepng($image);
imagedestroy($image);
}
security_image();
?>
I have no idea what I'm doing wrong. I've spent over 10 hours on this
"display text" issue. I don't understand and I am desperate for help. I even
downloaded working captcha version from other resources that break once I
upload it to my server. I have no idea whats going on. At first I thought
there was something wrong with my server but the fact that I can even create
the pixels, lines image means that it is at least working.
Please help!!!! :(
Thank you,
D a v i d S u m m e r s
IT Manager
Gulfcoast Ultrasound Institute
4615 Gulf Blvd. Suite 201
St. Pete Beach, FL 33706
Local: 727.363.4500
Toll Free: 1.800.619.1900
Fax: 727.363.0811
www.gcus.com <http://www.gcus.com/>