2011-01-08 111 views
1

我有captcha問題。在我的聯繫表格後,我給的驗證碼,它說錯誤captcha.how可我解決這個問題驗證碼問題

header('Content-type: image/jpeg'); 

$width = 50; 
$height = 24; 

$my_image = imagecreatetruecolor($width, $height); 

imagefill($my_image, 0, 0, 0xFFFFFF); 

// add noise 
for ($c = 0; $c < 40; $c++){ 
    $x = rand(0,$width-1); 
    $y = rand(0,$height-1); 
    imagesetpixel($my_image, $x, $y, 0x000000); 
    } 

$x = rand(1,10); 
$y = rand(1,10); 

$rand_string = rand(1000,9999); 
imagestring($my_image, 5, $x, $y, $rand_string, 0x000000); 

setcookie('tntcon',(md5($rand_string).'a4xn')); 

imagejpeg($my_image); 
imagedestroy($my_image); 
?> 

這是我的js驗證

if(document.getElementById("captcha").value==""){ 
      alert("Please type the code shown "); 
      document.getElementById("captcha").value=""; 
      document.getElementById("captcha").focus(); 
     return false; 
    } 

任何人可以說什麼是問題it.thanks in adv

回答

1

有一點是你應該使用會話而不是cookie。

另一件事是,也許你忘了檢查md5。

+0

我檢查了MD5但仍然有問題。 – magna 2011-01-08 07:41:44