i made a script to display random number in image mode for security code. I have 2 files:
1.login.php
<?php ob_start(); ?>
<html>
<body>
<?php
include("showImg.php");
?>
</body>
</html>
<?php ob_end_flush(); ?>
2.showImg.php
<?php
function make_seed() {
list($usec, $sec) = explode(' ', microtime());
return (float) $sec + ((float) $usec * 100000);
}
srand(make_seed());
$Number = rand(11111, 99999);
$imgWidth = 45;
$imgHeight = 20;
$img = ImageCreate ($imgWidth, $imgHeight);
$bgColor = ImageColorAllocate ($img, 255, 255, 255);
$txtColor= ImageColorAllocate ($img, 0, 0, 0);
ImageFilledRectangle ($img, 0, 0, $imgHeight, $imgHeight, $bgColor);
ImageString ($img, 4, 3, 3, $Number, $txtColor);
Header("Content-Type: image/jpeg");
ImageJpeg($img);
ImageDestroy($img);
?>
Before i used "ob_flush" the error was "headers alredy sent bla..bla..bla"
then i use ob_flush but the image still can't be displayed (only display strange characters).
Any idea how to fix this? Thanks friend..