This fully working script does not work when incorporated into a page. I have tried the following: a) put it into a function (function captcha()) and then called that function; b) created a separate page just for the ‘captcha’ script, and the included that page with the ‘include’ function. The result is always the same: [B]The image (…. path …) cannot be displayed, because it contains errors.
[code=php]
ob_start();
$image = imagecreate(80,30);
$bg_color = imagecolorallocate($image,102,102,102);
// —————– text ————————-
$letters = array(“a”,”b”,”c”,”d”,”e”,”f”,”g”,”h”,”i”,”j”,”k”,”l”,”m”,”n”,”o”,”p”,”q”,”r”,”s”,”t”,”u”,”v”,”w”,”x”,”y”,”z”);
$numbers = array(1,2,3,4,5,6,7,8,9,0);
$joined = array_merge($letters, $numbers);
$word = “”;
for($i=0;$i<5;$i++) {
$ran_pos = array_rand($joined);
$word .= $joined[$ran_pos];
}
$textColor = imagecolorallocate($image, 255,255,255);
imagestring($image, 5, 15, 5, $word, $textColor);
header(‘Content-type: image/png’);
imagepng($image);
ob_flush();
If I put the script into a function
[code=php]function captcha() {
….
….
}
and then call it, it does work [U]as long as I do NOT call it from within any HTML tags, like this:
[code=html]<body>
<?php captcha(); ?>
</body>
I don’t know what to do. Please help. (I wasn’t been able to find a solution in Google or anywhere else).