Moring everyone,

here's the problem. I've writted the code to make one of those random image verification thingys.

Everything works fine.
i generate the string and put it in the image.
but i am trying to extract the string to another variable and can't do it.

here is my function

function gen_rand_img() {

################################################################################################################################
//USER VARIABLES
$image_w	=	146; 		//image width
$image_h	=	50;			//image hight
$string_l	=	6;			//length of string




//DO NOT EDIT BELOW THIS LINE
################################################################################################################################
//FUNCTION VARIABLES

//create the image
$im 		=	ImageCreate($image_w, $image_h);

//set white and black
$white		=	ImageColorAllocate($im, 255, 255, 255);
$black		=	ImageColorAllocate($im, 0, 0, 0);

//generate the random string
srand((double)microtime()*1000000);

$string = md5(rand(0,9999)); // generate a random number

$new_string = substr($string, 17, $string_l); //grab string from string.

ImageFill($im, 0, 0, $black);

ImageString($im, 4, 70, 10, $new_string, $white);

Imagepng($im, 'rand_image.png');

}

i though that by echoing the $new_string var i would get the information that is getting injected into the png file. but i get an empty variable.

Any ideas?

thanks in advance.
chris

    I don't see the echo statement to output $new_string. If you want that to happen outside this function, then you will have to:

    return $new_string;

    at the end of the function so that the value is available outside the function. As in:

    $secret_number = gen_rand_img() ;

      sorry i forgot include the echo part of the code.

      i added the line

      return $new_string;

      I then called the function in another document

      $vcode = gen_rand_img();

      but when i call the var $new_string i still get an empty var.

      thanks,
      chris

        Write a Reply...