hey datasource....
Jeg har næsten fået det til at du nu med det eksempel du har linket til... dog har jeg et lille problem som jeg ikke kan løse håber du kan kaste lidt lys over det....
har vedlagt de to filer hvor jeg har koden
fil 1 gd_image_verify
<?php
// Velox Letum (2005)
// elementation@gmail.com
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);
}
// Set image height/width
$this->height = $height;
$this->width = $width;
// Start session
session_start();
}
function generate_string () {
// Create random string
$this->string = substr(sha1(mt_rand()), 17, 6);
// Set session variable
$_SESSION['gd_string'] = $this->string;
}
function verify_string ($gd_string) {
// Check if the original string and the passed string match...
if ($_SESSION['gd_string'] === $gd_string) {
return TRUE;
} else {
return FALSE;
}
}
function output_input_box ($name, $parameters = NULL) {
return '<input type="text" name="' . $name . '" ' . $parameters . ' /> ';
}
function create_image () {
// Seed string
$this->generate_string();
$this->im = imagecreatetruecolor($this->height, $this->width); // Create image
// Get width and height
$img_width = imagesx($this->im);
$img_height = imagesy($this->im);
// Define some common colors
$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);
// Background
imagefilledrectangle($this->im, 0, 0, $img_width, $img_height, $white);
// Ellipses (helps prevent optical character recognition)
imagefilledellipse($this->im, ceil(rand(5,$img_width - 5)), ceil(rand(0,$img_height)), 30, 30, $red);
imagefilledellipse($this->im, ceil(rand(5,$img_width - 5)), ceil(rand(0,$img_height)), 30, 30, $green);
imagefilledellipse($this->im, ceil(rand(5,$img_width - 5)), ceil(rand(0,$img_height)), 30, 30, $blue);
// Borders
imagefilledrectangle($this->im, 0, 0, $img_width, 0, $black);
imagefilledrectangle($this->im, $img_width - 1, 0, $img_width - 1, $img_height - 1, $black);
imagefilledrectangle($this->im, 0, 0, 0, $img_height - 1, $black);
imagefilledrectangle($this->im, 0, $img_height - 1, $img_width, $img_height - 1, $black);
imagestring ($this->im, 5, intval(($img_width - (strlen($this->string) * 9)) / 2), intval(($img_height - 15) / 2), $this->string, $black); // Write string to photo
}
function output_image() {
$this->create_image(); // Generate image
header("Content-type: image/jpeg"); // Tell the browser the data is a JPEG image
imagejpeg($this->im); // Output Image
imagedestroy($this->im); // Flush Image
}
}
?>
fil 2 gd_image.php
<?php
// Velox Letum (2005)
// elementation@gmail.com
// Require the class code...
require ('gd_image_verify.php');
// Initialize class
$gd = new gd_verification();
if (isset($_POST['submit'])) {
if ($gd->verify_string($_POST['gd_string'])) {
$result = 'User input matches image string.';
} else {
$result = 'User input does not match image string.';
}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "
http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="
http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<title>GD Image Verification Class Example</title>
<meta name="Generator" content="Stone's WebWriter 4">
</head>
<body>
<div style="text-align:center;">
<h1>GD Image Verification Class Example</h1>
<? echo $result; ?><br /><br />
<form name="gd_verify" method="POST" action="<? echo $PHP_SELF; ?>">
<img src="gd_image.php" alt="Verification Image" /><br /><br />
<? echo $gd->output_input_box('gd_string'); ?><br /><br .>
<input type="submit" name="submit" value="Submit" />
</form>
</div>
</body>
</html>
Koden vil bare ikke vise det billedet der kommer bare et kryds... men hvis jeg skriver
$gd->output_image();
så kommer der et billede... men så virker alt det andet med formen ikke