Jump to content

Captcha code Error


peranha

Recommended Posts

Thanks, that fixed that error, but now it will not set the $str in a session for me to check on submit.  Here is the code.

 

<?php
$string = "abcdefghijklmnopqrstuvwxyz0123456789";
$str = NULL;
for($i=0;$i<6;$i++){
    $pos = rand(0,36);
    $str .= $string[$pos];
}
$textbox = imagettfbbox($fontSize, 0, $font, $str) or die('Error in imagettfbbox function');
$x = ($width - $textbox[4])/2;
$y = ($height - $textbox[5])/2;
imagettftext($img_handle, $fontSize, 0, $x, $y, $txtColor, $font , $str) or die('Error in imagettftext function');
for($i=0;$i<$lineCount;$i++){
    $x1 = rand(0,$width);$x2 = rand(0,$width);
    $y1 = rand(0,$width);$y2 = rand(0,$width);
    imageline($img_handle,$x1,$y1,$x2,$y2,$lineColor);
}
session_start();
header('Content-Type: image/jpeg');
imagejpeg($img_handle,NULL,100);
imagedestroy($img_handle);

$_SESSION['img_number'] = $str;
?>

Link to comment
https://forums.phpfreaks.com/topic/138258-captcha-code-error/#findComment-722904
Share on other sites

but now it will not set the $str in a session for me to check on submit

 

What tests have you done?

 

echo out the session, and it is empty, not set, moved the $_SESSION['img_number'] around, and still nothing.  Submitted the code, and it does not validate, keeps giving me "Undefined index: img_number" 

Link to comment
https://forums.phpfreaks.com/topic/138258-captcha-code-error/#findComment-722919
Share on other sites

Id replace this....

 

$string = "abcdefghijklmnopqrstuvwxyz0123456789";
$str = NULL;
for($i=0;$i<6;$i++){
    $pos = rand(0,36);
    $str .= $string[$pos];
}

 

with....

 

$arr = array_merge(range('a','z'),range(0,9));
$str = '';
for ($i = 0; $i < 6; $i++) {
    $str .= $arr[rand(0,36)];
}

Link to comment
https://forums.phpfreaks.com/topic/138258-captcha-code-error/#findComment-722923
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.