Am trying to write a script that will create an image and write randomly generated numbers on each of the images in a loop. Everything is almost working except that it is only the last generated numbers will be written in all the images.. Please can anyone help me with this so that as the numbers are being generated in a loop, it will be written on each of the image seperately, so that i will have images with different values written on them.
Below is my codes: the first one ‘gen.php’ is the one that generates the numbers, and outputs it with an image that will be created with the second scripts ‘img.php’.
(gen.php):
<?php
session_start();
$num = 5; // Assume we want to generate just 5 differnt set of numbers
for ($j = 1; $j <= $num; $j++) {
$md5 = md5(rand(0, 999));
$pin = substr($md5, 1, 10);
$pin = strtoupper($pin);
$_SESSION[‘pin’] = $pin;
echo “<img src=img.php /><br><br>”;
}
?>
(img.php):
<?php
session_start();
$pin = $_SESSION[‘pin’];
$img = imagecreate(200,50); //Create the image resource
//We are making three colors, white, black and gray
$white = ImageColorAllocate($img, 255, 255, 255);
$black = ImageColorAllocate($img, 0, 0, 0);
$grey = ImageColorAllocate($img, 204, 204, 204);
ImageFill($img, 0, 0, $grey);
imagestring($img, 10, 30, 20, $pin, $white); //Add randomly generated string in white to the image
header(“Content-Type: image/png”); //Tell the browser what kind of file is come in
imagepng($img); //Output the newly created image in png format
ImageDestroy($img); //Free up resources
?>
PLEASE HELP ME !!