Saturday 15 February 2014

php - Creating captcha word not working -


Im trying to create a captcha word image, but the image is not visible what I've done so far Is:

  & lt ;? Php session_start (); $ String = ''; For ($ i = 0; $ i & lt; 5; $ i ++) {$ string} = Chr (Rand (97, 122)); } $ _SESSION ['random_code'] = $ string; $ Dir = 'fonts /'; $ Image = imagecreatetruecolor (170, 60); $ Black = imagecolorallocate ($ image, 0, 0, 0); $ Color = imagecolorallocate ($ image, 200, 100, 90); // red $ white = imagecolorallocate ($ image, 255, 255, 255); Imagefilledrectangle ($ image, 0,0,200,100, white $); Fictional picture ($ image, 30, 0, 10, 40, $ alt, $ dir. "Arial.ttf", $ _SESSION ['rand_code']); Header ("content-type: image / PNG"); Imagepng ($ image); ? & Gt;   

I do not know why it is not working Any help would be appreciated.

Why do you need a captcha? ReCAPTCHA, no?
OK .. ..

  // Generate random number and store in session $ randomnum = rand (1000, 99 99); $ _SESSION ['Random'] = MD5 ($ Random); // generated image $ im = imagecreatetruecolor (100, 38); // color: $ white = imagecolorallocate ($ im, 255, 255, 255); $ Gray = imagecolorallocate ($ im, 128, 128, 128); $ Black = imagecolorallocate ($ im, 0, 0, 0); ImageFilterTagon ($ im, 0, 0, 200, 35, $ ​​black); // Path for fonts: $ font = 'font / font.TTF'; // Draw Text: ColorFacts ($ im, 35, 0, 22, 24, $ gray, $ font, $ random); Fictional picture ($ im, 35, 0, 15, 26, $ white, $ font, $ randomnum); // stop client side caching header ("End: Mercury, 1 January 1997 00:00 GMT"); Header ("Last-Modified:" .GMDAT ("D, Dm YH: I: S"). "GMT"); Header ("Cash-Control: No-Store, No-Cash, Sure-Modify"); Header ("cache-control: post-check = 0, pre-check = 0", false); Header ("Prestama: no-cache"); // Send the image to the browser title ("Content-Type: Image / GIF"); Imagegif ($ im); Imagedestroy ($ im);   

More Forms

  & lt; Form method = "post" action = "write.php" & gt; & Lt; Input class = "input" type = "text" name = "norobot" /> & Lt; Img src = "captcha.php" /> & Lt; Input type = "submit" value = "submit" /> & Lt; / Form & gt;   

and write.php

  session_start (); If you pass the encoding exam (if MD5 ($ _ $ POST ['norobot']) == $ _SESSION ['Random 2']) // Here, you will say, "O great, it seems that you There are no robots "; } Else {// If you fail in the captcha test, then you place the code to execute "You are very naughty robots!"; }    

No comments:

Post a Comment