php - Adding more number values to CAPTCHA -


i wrote few months ago , other day realized made mistake. captcha displays lowercase characters a-z (97-122). how add uppercase a-z (65-90) , 0-9 (48-57)? have area in need of repair separated rest.

i first tried doing:

 ($i = 0; $i < captchacharas; $i++) {   $passphrase .= chr (rand (48, 57));   $passphrase .= chr (rand (65, 90));   $passphrase .= chr (rand (97, 122));  } 

but made things twice long "a-z". tried:

 ($i = 0; $i < captchacharas; $i++) {   $passphrase .= chr (rand (48, 57), (65, 90), (97, 122));  } 

with no success. replaced ), ( ) + ( , didn't work. help.

php captcha:

<?php  session_start ();  // sets important definitions  define ("captchacharas", 7); // number of characters in pass-phrase  define ("captchawidth", 100); // width of image  define ("captchaheight", 40); // height of image  // generates random pass-phrase  $passphrase = "";    // characters used  ($i = 0; $i < captchacharas; $i++) {   // "48" - "57" = "0" - "9"   // "65" - "90" = "a" - "z"   // "97" - "122" = "a" - "z"   $passphrase .= chr (rand (97, 122));  }    // store encrypted pass-phrase in session variable  // connects form.  $_session ["passphrase"] = sha1 ($passphrase);  // creates image  $img = imagecreatetruecolor (captchawidth, captchaheight);  // set background, text , line\dots colors  $backgroundcolor = imagecolorallocate ($img, 255, 255, 255); // current color: white  $textcolor = imagecolorallocate ($img, 0, 0, 0); // current color: black  $bordercolor = imagecolorallocate ($img, 64, 64, 64); // current color: dark gray  // fills background  imagefilledrectangle ($img, 0, 0, captchawidth, captchaheight, $backgroundcolor);  // formats  imagettftext ($img, 18, 0, 5, captchaheight - 5, $textcolor, "captcha-1.ttf", $passphrase);  // draws random lines here , there.  ($i = 0; $i < 5; $i++) {imageline ($img, 0, rand () % captchaheight, captchawidth, rand () % captchaheight, $bordercolor);}  // puts in random dots here , there.  ($i = 0; $i < 50; $i++) {imagesetpixel ($img, rand () % captchawidth, rand () % captchaheight, $bordercolor);}  // output image ".png" file using header  header ("content-type: image/png");  imagepng ($img);  imagedestroy ($img); ?> 

how generating captcha this:

define( 'captchacharas', 7 ); // allowed characters  $letters    = 'abcdefghijklmnopqrstuvxyzabcdefghijklmnopqrstuvxyz0123456789'; $letters_no = strlen( $letters ); $passphrase = '';  // generate capcha ( $i=0; $i<captchacharas; $i++ ) {     $passphrase .= $letters{rand( 0, $letters_no )}; }  // use used before echo $passphrase; 

Comments

Popular posts from this blog

java - Static nested class instance -

c# - Bluetooth LE CanUpdate Characteristic property -

JavaScript - Replace variable from string in all occurrences -