vbbit
Apr 24th, 2007, 01:21 PM
Hi guys, I have the code below in one file called img.php, but I odn't know why everytime I refresh the IE, the image code never got changed.
<?php
// initialize session
session_start();
// send header so telling the connectiont that we are about to send an image
header("Content-Type: image/png");
// generate 5 digits random number
$rand = rand(10000, 99999);
// create the hash for the random numbers and put them in the session
$_SESSION['img_random_value'] = md5($rand);
// create the image
$image = imagecreate(60, 30);
// set the background color to white - this has to come first
$bgColor = imagecolorallocate($image, 255, 255, 255);
// set the text color to black
$txtColor = imagecolorallocate($image, 0, 0, 0);
// write the image
//imagefill($image, 0, 0, $bgColor);
imagestring($image, 5, 5, 8, $rand, $txtColor);
// output it to browser
imagepng($image, "verify.png");
// destroy the image to free up the server memory
imagedestroy($image);
?>
<tr>
<td width="33%">
<p style="margin-left: 10"><font color="#FF0000">* </font>Verify Image
Code as shown</td>
<td width="67%" valign="top"><input type="text" name="random" size="5">
<img src="verify.png" width="60" height="30"></td>
</tr>
<?php
// initialize session
session_start();
// send header so telling the connectiont that we are about to send an image
header("Content-Type: image/png");
// generate 5 digits random number
$rand = rand(10000, 99999);
// create the hash for the random numbers and put them in the session
$_SESSION['img_random_value'] = md5($rand);
// create the image
$image = imagecreate(60, 30);
// set the background color to white - this has to come first
$bgColor = imagecolorallocate($image, 255, 255, 255);
// set the text color to black
$txtColor = imagecolorallocate($image, 0, 0, 0);
// write the image
//imagefill($image, 0, 0, $bgColor);
imagestring($image, 5, 5, 8, $rand, $txtColor);
// output it to browser
imagepng($image, "verify.png");
// destroy the image to free up the server memory
imagedestroy($image);
?>
<tr>
<td width="33%">
<p style="margin-left: 10"><font color="#FF0000">* </font>Verify Image
Code as shown</td>
<td width="67%" valign="top"><input type="text" name="random" size="5">
<img src="verify.png" width="60" height="30"></td>
</tr>