Reply to Cannot generate random image for form security - help

Your name:

Reply:


Posted by comp.lang.php on 04/04/06 01:00

[PHP]
/**
* Generate the random security image
*
* @access public
* @param $willUseFilePath (default false) boolean to determine if you
will be using a file path
* @param mixed $filePath (optional) file path to store image resource
object contents
* @see actual_path
*/
function generate($willUseFilePath = false, $filePath = '') {

$type = $this->getImageType();
$length = $this->getLength();
if ($willUseFilePath && $filePath) $this->setFilePath($filePath);

$text = $this->generateText();
$fileName = $this->getFileName();
if (!$fileName) {
$fileName = $this->generateFileName();
$this->setFileName($fileName);
}

// create an temporary image from an image file
if (is_file(actual_path("$filePath/$fileName"))) $msg = eval('$image
= imagecreatefrom' . $type . '("' . $filePath . '/' . $fileName .
'");');
if (!$image && strcmp($type, 'gif') != 0) $image =
imagecreatetruecolor(150, 30); else $im = imagecreate(100, 50) or
die("Cannot Initialize new GD image stream");

// get a color from the image (in this case, yellow)
$orange = imagecolorallocate($image, 220, 210, 60);

// Now we need to get widh and height of the image, so that we can
center the key on the image, so that it does not go outside of the
borders or look strange
$width = (imagesx($image) - 7.5 * strlen($text)) / 2;
$height = (imagesy($image) - 7.5) / 2;

// here we write the key (the string) on the image
imagestring($image, 3, $width, $height, $text, $orange);

// now create the final image
$msg = eval('image' . $type . '($image);');


// to free up results, we need to destroy the temporary image.
imagedestroy($image);

if (is_file(actual_path("$filePath/$fileName")) || $msg) {
$this->setSession($fileName, $text);
} else {
$this->dbAP->isSuccessful = false;
$this->dbAP->setErrorArray(array('action' => 'Unable to generate
random image for form security: ' . nl2br($msg)));
}
}

[/PHP]

This class method is supposed to generate one of those random images
you see on forms, you know, with the letters and numbers all mixed up
for people to type it in for security and repost protection purposes.

This method, however, fails. No errors, no warnings, no notices, not
even a broken image, it just DIES on the spot, completely, stops dead
on the line:

[PHP]
if (!$image && strcmp($type, 'gif') != 0) $image =
imagecreatetruecolor(150, 30); else $im = imagecreate(100, 50) or
die("Cannot Initialize new GD image stream");
[/PHP]

I've no clue what to do.

Thanx
Phil

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация