1Danke
ERLEDIGT
NEIN
NEIN
ANTWORTEN
7
7
ZUGRIFFE
254
254
EMPFEHLEN
-
Hallo,
ich habe das Captcha Tutorial gemacht, leider kommt immer ein Fehler. Ich habe schon alles möglich durchprobiert. Im Firefox kommt nur ein kaputtes Bild, bzw. nur der Pfad zur aktuellen Datei. Im Internet Explorer 7 kommt diese Meldung:
Woher kommen die HTML-Tags?<br /> <b>Fatal error</b>: Call to undefined function: imagettftext() in <b>/fvol1/wwwhome/dev.lynet.de/www/tlorenz_webcam/captcha.php</b> on line <b>52</b><br />
GD-Lib ist aktiviert.
Der COde
Code :1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
<?php $CAPTCHA_LENGTH = 5; // Länge der Captcha-Zeichenfolge, hier fünf Zeichen $FONT_SIZE = 18; // Schriftgröße der Zeichen in Punkt $IMG_WIDTH = 170; // Breite des Bild-Captchas in Pixel $IMG_HEIGHT = 60; // Höhe des Bild-Captchas in Pixel // Liste aller verwendeten Fonts $FONTS[] = 'arialf'; // Unser Zeichenalphabet $ALPHABET = array('A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'Q', 'J', 'K', 'L', 'M', 'N', 'P', 'R', 'S', 'T', 'U', 'V', 'Y', 'W', '2', '3', '4', '5', '6', '7'); // Wir teilen dem Browser mit, dass er es hier mit einem JPEG-Bild zu tun hat. header('Content-Type: image/jpeg', true); // Wir erzeugen ein leeres JPEG-Bild von der Breite IMG_WIDTH und Höhe IMG_HEIGHT $img = imagecreatetruecolor($IMG_WIDTH, $IMG_HEIGHT); // Wir definieren eine Farbe mit Zufallszahlen // Die Farbwerte sind durchgehend und absichtlich hoch (200 - 256) gewählt, // um eine "leichte" Farbe zu erhalten $col = imagecolorallocate($img, rand(200, 255), rand(200, 255), rand(200, 255)); // Wir füllen das komplette Bild mit der zuvor definierten Farbe imagefill($img, 0, 0, $col); $captcha = ''; // Enthält später den Captcha-Code als String $x = 10; // x-Koordinate des ersten Zeichens, 10 px vom linken Rand for($i = 0; $i < $CAPTCHA_LENGTH; $i++) { $chr = $ALPHABET[rand(0, count($ALPHABET) - 1)]; // ein zufälliges Zeichen aus dem definierten Alphabet ermitteln $captcha .= $chr; // Der Zeichenfolge $captcha das ermittelte Zeichen anfügen $col = imagecolorallocate($img, rand(0, 199), rand(0, 199), rand(0, 199)); // einen zufälligen Farbwert definieren $font = $FONTS[rand(0, count($FONTS) - 1)]; // einen zufälligen Font aus der Fontliste FONTS auswählen $y = 25 + rand(0, 20); // die y-Koordinate mit einem Mindestabstand plus einem zufälligen Wert festlegen $angle = rand(0, 30); // ein zufälliger Winkel zwischen 0 und 30 Grad /* * Diese Funktion zeichnet die Zeichenkette mit den * gegeben Parametern (Schriftgröße, Winkel, Farbe, TTF-Font, usw.) * in das Bild. */ imagettftext($img, 20, 28, 30, 140, $font_c, 'arialf', 'PHP3/4 - Die Befehlsreferenz'); $dim = imagettfbbox($FONT_SIZE, $angle, $font, $chr); // ermittelt den Platzverbrauch des Zeichens $x += $dim[4] + abs($dim[6]) + 10; // Versucht aus den zuvor ermittelten Werten einen geeigneten Zeichenabstand zu ermitteln } imagejpeg($img); // Ausgabe des Bildes an den Browser imagedestroy($img); // Freigeben von Speicher ?>
-
Siehe php.net
Diese werden bei dir wohl nicht installiert sein.Diese Funktion erfordert sowohl die GD- als auch die » FreeType-Bibliothek.
-
Hi ich hab da mal die folgende Klasse für ein eigenes Projekt geschrieben. Kam leider nie zum Einsatz. Habe sie auch nie getestet. Kannst du aber gerne nutzen und wenn sie nicht funktioniert, kannst du dich ja einfach mal melden.
MfG, Andy
//EDIT: Habe das ganze mal kurz getestet und schnell etwas überarbeitet. Ist noch immer nicht perfekt, wird allerdings heute Abend alles noch gemacht.PHP-Code:<?php
error_reporting(E_ALL);
/***
* Class Captcha
*
* The Captcha class allows creating a captcha that
* that should prefent bots from misuse of your
* forms. It generates an image that shows some
* characters, which the user must type
* in correctly to post your form.
*
* @package Captcha
* @version 0.4
* @author Andreas Wilhelm <Andreas2209@web.de>
* @copyright Andreas Wilhelm
**/
class Captcha
{
// Captcha Variables
private $length;
private $highlights;
/**
* Constructor - Is called when the class is instanced
*
* @access public
* @param Int $width
* @param Int $height
* @param Int $highlights
* @return boolean
*/
public function __construct($length=5, $highlights=5)
{
$this->length = $length;
$this->width = imagefontwidth(5) * $length + 25;
$this->height = imagefontheight(5) + 20;
$this->highlights = $highlights;
session_start();
header("content-type: image/gif");
$str = $this->createText();
$this->createImage($str);
$this->background();
$this->spots();
$this->stripes();
$this->border();
$this->insertText($str);
$final = $this->getObject();
imagegif ($final);
imagedestroy ($final);
}
/**
* createText() - Creates a string with letters and numbers
*
* @access public
* @return String
*/
public function createText()
{
$abc = range('a', 'z');
$num = range(0,9);
$mix = array_merge($abc, $num);
shuffle($mix);
$text = '';
for ($i = strlen($text); $i < $this->length; $i++)
{
$text .= $mix[$i];
}
$_SESSION['captcha'] = $text;
return $text;
}
/**
* createImage() - Creates a image for the captcha
*
* @access public
* @param Str $str
* @return Obj
*/
public function createImage($str)
{
$this->font = mt_rand(3,5);
$this->imgwidth = (strlen($str)*imagefontwidth($this->font)) + 10;
$this->imgheight = imagefontheight($this->font) + 10;
if($this->imgwidth < $this->width OR $this->imgheight < $this->height)
{
$this->imgwidth = $this->width;
$this->imgheight = $this->height;
}
$this->width = $this->imgwidth;
$this->height = $this->imgheight;
$this->img = imagecreatetruecolor($this->width, $this->height);
}
/**
* background() - Creates the image-background for the captcha
*
* @access public
* @return NONE
*/
public function background()
{
$black = imagecolorallocate($this->img, 0, 0, 0);
imagefill($this->img, 0, 0, $black);
for ($i = 0; 175 >= round(175 / $this->height * $i); $i++)
{
$color[] = imagecolorallocate($this->img, round(175 / $this->height * $i), round(175 / $this->height * $i), round(175 / $this->height * $i));
imageline($this->img, 0, $i, $this->width, $i, $color[$i]);
}
}
/**
* spots() - Creates the spots for the captcha
*
* @access public
* @return NONE
*/
public function spots()
{
$color = $this->colors($this->img);
for ($j = 0; $j < ($this->highlights/3); $j++)
{
$x = mt_rand(0, $this->width);
$y = mt_rand(0, $this->height);
$width = rand(5, 7);
$height = rand(5, 7);
imagefilledellipse ($this->img, $x, $y, $width, $height, $color[$j]);
}
}
/**
* stripes() - Creates the stripes for the captcha
*
* @access public
* @return NONE
*/
public function stripes()
{
$color = $this->colors($this->img);
for ($j = 0; $j < ($this->highlights/3); $j++)
{
$x_start = mt_rand(0, $this->width);
$y_start = mt_rand(0, $this->height);
$x_end = mt_rand(0, $this->width);
$y_end = mt_rand(0, $this->height);
imageline($this->img, $x_start, $y_start, $x_end, $y_end, $color[$j]);
}
}
/**
* polygon() - Creates a row of polygons
*
* @access public
* @return NONE
*/
public function polygon()
{
$color = $this->colors($this->img);
for ($j = 0; $j < ($this->highlights/3); $j++)
{
$size = mt_rand(3, 25);
$radian = mt_rand(7, 10);
$angle = 360 / $size;
$x = mt_rand(0, $this->width);
$y = mt_rand(0, $this->height);
for ($k = 0; $k < ($this->highlights/3); $k++)
{
$spots[] = $x * cos($k * $angle);
$spots[] = $y * sin($k * $angle);
}
ksort($spots);
imagefilledpolygon ($this->img, $spots, (sizeof($spots)/2), $color[$j]);
}
}
/**
* border() - Creates the border of the captcha
*
* @access public
* @return NONE
*/
public function border()
{
$blue = imagecolorallocate($this->img, 188, 210, 238);
imageline($this->img, 0, 0, $this->width, 0, $blue);
imageline($this->img, 0, $this->height - 1, $this->width, $this->height - 1, $blue);
imageline($this->img, 0, 0, 0, $this->height, $blue);
imageline($this->img, $this->width - 1, 0, $this->width - 1, $this->height, $blue);
}
/**
* colors() - Returns an array of colors
*
* @access public
* @return Array
*/
public function colors()
{
$colors = array();
for ($i = 0; $i < ($this->highlights/3); $i++)
{
$col = rand(0, 255);
$colors[] = imagecolorallocate($this->img, $col, $col, $col);
}
shuffle($colors);
return $colors;
}
/**
* insertText() - Inserts the text into the captcha
*
* @access public
* @param Str $str
* @return NONE
*/
public function insertText($str)
{
$blue = imagecolorallocate($this->img, 188, 210, 238);
imagestring($this->img, 5, 10, 10, $str, $blue);
}
/**
* getObject() - Returns the image-object
*
* @access public
* @return NONE
*/
public function getObject()
{
return $this->img;
}
}
?>Geändert von Avedo (20.08.08 um 16:23 Uhr)
-
Danke für eure Hilfe!
Ich habe nochmal in der PHP Info geschaut, von FreeType-Bibliothek steht da rein gar nichts. Deswegen läuft das Script von mir wohl nicht.
@Catull
Deine PHP Kenntnisse übersteigen mein Know-How, deswegen kann ich dort nicht viel verändern, bei mir kommt aber folgende Fehlermeldung:
Parse error: syntax error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /fvol1/wwwhome/dev.lynet.de/www/tlorenz_webcam/captcha.php on line 21Code :1
L. 21: private $length;
-
Du verwendest PHP4 und der Code ist PHP5 only. private und public gab es bei der 4er Version noch nicht.
Du solltest mal deinen Provider anschreiben und ihn auf http://www.tutorials.de/blog/dennis-...4-ist-tot-891/ hinweisen. PHP4 ist out of Date und es gibt auch keine neuen Patches mehr.Geändert von Michael Engel (21.08.08 um 13:25 Uhr)
Der Computer ist die logische Weiterentwicklung des Menschen: Intelligenz ohne Moral.
-
Naja an der Klasse sollst du auch überhaupt nichts ändrn. Ich wollte sie nochmal auf einen neueren Stand bringen, da es schon etwas her ist, dass ich diese geschrieben habe. Allerdings kannst du sie gerne verwenden. Dazu solltest du aber entweder zu einem anständigen Anbieter wechseln oder deinen überzeugen auf PHP 5 umzusteigen. Ich kann dir zum Beispiel den kostenlosen und werbefreien Webspace von piranho.de empfehlen. Ist für einen Anfänger vollkommen ausreichend. Kann dir später auch noch ein Funktionsbeispiel der Klasse schreiben.
MfG, Andy
-
Okay danke, mit PHP 5 läuft dein Vorschlag, Catull. Super, vielenDank

Bin noch offline am rumprobieren, sieht aber bisher gut aus!
-
Danke! Wollte es eigentlich noch ermöglichen die Hintergrundfarbe zu ändern, habe ich aber nicht mehr geschafft. Kommt vielleicht am Montag.
MfG, Andy
Ähnliche Themen
-
Captcha will nicht
Von Do_0mi im Forum PHPAntworten: 16Letzter Beitrag: 04.03.09, 19:59 -
captcha Fehler
Von Binio im Forum PHPAntworten: 4Letzter Beitrag: 28.04.08, 15:40 -
[JSP] Captcha
Von SeeSharpNewBee im Forum Enterprise Java (JEE, J2EE, Spring & Co.)Antworten: 0Letzter Beitrag: 13.02.08, 14:26 -
Text Captcha
Von Flex im Forum PHPAntworten: 16Letzter Beitrag: 18.05.07, 07:04 -
Captcha sicher?
Von ThaNewbie im Forum PHPAntworten: 4Letzter Beitrag: 17.05.07, 11:37





Zitieren
Login






[PHP][Snippet] Array zu XML konvertieren