mylinear
04-04-2006, 04:33 AM
I've been trying out some image verification code. The below is a simple test script to test out the functionality.
Here is what happens.
1. When first run, a new image is created and displayed on the browser.
2. When the refresh button is pressed, a new image is created and the new image is displayed on the browser.
3. When the Submit button is pressed, the script is re-called and re-run and a new image is created. This can be verified by directly viewing the test.png file. However, the new image is not displayed on the browser. The old image is still shown.
My questions are:
1. Why is it that a refresh will display the new image while the Submit does not, even though both re-run the script?
2. Is this a browser caching issue?
3. If it is a caching issue, what should be done to get the desired results?
<?php
// Create image
$random = rand(1000, 9999);
$image = imagecreate(60, 40);
$background = imagecolorallocate($image, 0, 0, 0);
$text = imagecolorallocate($image, 255, 255, 255);
imagestring($image, 5, 10, 10, $random, $text);
imagepng($image, "test.png");
imagedestroy($image);
?>
<html>
<head>
<title>Test</title>
</head>
<body>
<?php
print date("r");
print "<br />";
?>
<img src="test.png" />
<form name="Test" action="test.php" method="POST">
<input type="submit" name="Submit" value="Submit" />
</form>
</body>
</html>
Here is what happens.
1. When first run, a new image is created and displayed on the browser.
2. When the refresh button is pressed, a new image is created and the new image is displayed on the browser.
3. When the Submit button is pressed, the script is re-called and re-run and a new image is created. This can be verified by directly viewing the test.png file. However, the new image is not displayed on the browser. The old image is still shown.
My questions are:
1. Why is it that a refresh will display the new image while the Submit does not, even though both re-run the script?
2. Is this a browser caching issue?
3. If it is a caching issue, what should be done to get the desired results?
<?php
// Create image
$random = rand(1000, 9999);
$image = imagecreate(60, 40);
$background = imagecolorallocate($image, 0, 0, 0);
$text = imagecolorallocate($image, 255, 255, 255);
imagestring($image, 5, 10, 10, $random, $text);
imagepng($image, "test.png");
imagedestroy($image);
?>
<html>
<head>
<title>Test</title>
</head>
<body>
<?php
print date("r");
print "<br />";
?>
<img src="test.png" />
<form name="Test" action="test.php" method="POST">
<input type="submit" name="Submit" value="Submit" />
</form>
</body>
</html>
