Jump to content

Creating images using php


Cagecrawler

Recommended Posts

I'm trying to create an image to use for registration to stop bots.  I've managed to create the image, but when I try to insert anything into the file, or insert it into another file, I get the following error:
[code]
The image “register.php” cannot be displayed, because it contains errors.
[/code]
In this case, the image code is in key.php, and the file I'm trying to insert it into is called register.php.

Can anybody help please?
Link to comment
https://forums.phpfreaks.com/topic/34358-creating-images-using-php/
Share on other sites

Here's key.php:

[code]<?php
function genText($length) {
$p_chars=md5(time()); // can be any set of characters
while(strlen($out_str)< $length)
{
$out_str.= $p_chars{rand()%(strlen($p_chars))};
}
return $out_str;
}

$rand_string = genText(8);
header ("Content-type: image/png");
$im = imagecreate(60, 20);
$bg = imagecolorallocate($im, 0, 255, 255);
$text_color = imagecolorallocate($im, 0, 0, 255);

imagestring($im, 2, 5, 3,$rand_string, $text_color);
imagepng($im);
imagedestroy($im);
?>[/code]

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.