Hi everyone!
I have this code:
class GD_Verification
{
var $IM = NULL;
var $String = NULL;
var $Height;
var $Width;
function GD_Verification($Height = 150, $Width = 35, $SID = NULL)
{
if ($SID != NULL)
{
session_name($SID);
}
$this->Height = $Height;
$this->Width = $Width;
}
function Generate_String()
{
$this->String = substr(sha1(mt_rand()), 17, 6);
$_SESSION['GD_String'] = $this->String;
}
function Verify_String($GD_String)
{
if ($_SESSION['GD_String'] === $GD_String)
{
return true;
}
else
{
return false;
}
}
function Create_Input_Box($Name, $Margin)
{
$Master = '<label for="' . $Name . '">Validation Code: </label>';
$Master .= '<input type="text" name="' . $Name . '" id="' . $Name . '" style="margin-left: ' . $Margin . 'px;" />';
return $Master;
}
function Create_Image()
{
$this->Generate_String();
$this->IM = imagecreatetruecolor($this->Height, $this->Width);
$Image_Width = imagesx($this->IM);
$Image_Height = imagesy($this->IM);
$Black = imagecolorallocate($this->IM , 0 , 0 , 0);
$White = imagecolorallocate($this->IM , 255 , 255 , 255);
$Red = imagecolorallocatealpha($this->IM , 255 , 0 , 0 , 75);
$Green = imagecolorallocatealpha($this->IM , 0 , 255 , 0 , 75);
$Blue = imagecolorallocatealpha($this->IM , 0 , 0 , 255 , 75);
$End = imagecolorallocatealpha($this->IM , ceil(rand(0, 255)), ceil(rand(0, 255)), ceil(rand(0, 255)), ceil(rand(0, 255)));
imagefilledrectangle($this->IM, 0, 0, $Image_Width, $Image_Height, $White);
// Ellipses (helps prevent optical character recognition)
imagefilledellipse($this->IM, ceil(rand(5, $Image_Width - 5)), ceil(rand(0, $Image_Height)), 30, 30, $Red);
imagefilledellipse($this->IM, ceil(rand(5, $Image_Width - 5)), ceil(rand(0, $Image_Height)), 30, 30, $Green);
imagefilledellipse($this->IM, ceil(rand(5, $Image_Width - 5)), ceil(rand(0, $Image_Height)), 30, 30, $Blue);
imagefilledellipse($this->IM, ceil(rand(5, $Image_Width - 5)), ceil(rand(0, $Image_Height)), 30, 30, $End);
imagefilledrectangle($this->IM, 0 , 0, $Image_Width, 0, $Black);
imagefilledrectangle($this->IM, $Image_Width - 1, 0, $Image_Width - 1, $Image_Height - 1, $Black);
imagefilledrectangle($this->IM, 0, 0, 0, $Image_Height - 1, $Black);
imagefilledrectangle($this->IM, 0, $Image_Height - 1, $Image_Width, $Image_Height - 1, $Black);
imagestring ($this->IM, 5, intval(($Image_Width - (strlen($this->String) * 9)) / 2), intval(($Image_Height - 15) / 2), $this->String, $Black);
}
function Output_Image()
{
$this->Create_Image();
header("Content-type: image/jpeg");
imagejpeg($this->IM);
imagedestroy($this->IM);
}
}
Can someone modify that so the image is saved to a temporary file instead of displaying directly?
Cheers,
Ryan Jones