Hi Leute,
ich hab mir gerade eine eigene Captcha Klasse geschrieben. Auf meinem Localhost klappt alles wunderbar, nur wenn ich die ganze Geschichte auf den Server lade dann tauchen plötzliche Probleme auf.
Das Script liegt auf http://www.tanzen.com/index/index/captcha.jpg
Wenn Ihr nun dort mehrmals refreshed dann kann es pasieren das kein Bild mehr angezeigt wird? Warum? Wie gesagt auf dem Localhost kann ich so oft ich will refreshen.
Hier mal die Klasse:
ich hab mir gerade eine eigene Captcha Klasse geschrieben. Auf meinem Localhost klappt alles wunderbar, nur wenn ich die ganze Geschichte auf den Server lade dann tauchen plötzliche Probleme auf.
Das Script liegt auf http://www.tanzen.com/index/index/captcha.jpg
Wenn Ihr nun dort mehrmals refreshed dann kann es pasieren das kein Bild mehr angezeigt wird? Warum? Wie gesagt auf dem Localhost kann ich so oft ich will refreshen.
Hier mal die Klasse:
PHP:
<?php
class Captcha extends Plugin
{
private $charset = 'ABCDEFHKLMNPRSTUVWYZ34569';
private $captchaLength = 5;
private $captchaFonts = array( 'images/captcha/fonts/asimovf',
'images/captcha/fonts/actionjf',
'images/captcha/fonts/zacharyf');
private $fontSize = 20;
private $imageHeight = 50;
private $imageWidth = 160;
public function getCaptcha() {
$this->createImage();
header("Expires: Sun, 1 Jan 2000 12:00:00 GMT");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . "GMT");
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
header("Content-type: image/png");
imagepng($this->captcha); // Ausgabe des Bildes an den Browser
imagedestroy($this->captcha); // Freigeben von Speicher
$_SESSION['captchaCode'] = $this->captchaCode;
die();
}
private function createImage() {
$this->captcha = imagecreatetruecolor($this->imageWidth, $this->imageHeight);
$backgroundColor = imagecolorallocate($this->captcha, rand(200, 255), rand(200, 255), rand(200, 255));
imagefill($this->captcha, 0, 0, $backgroundColor);
$this->drawBackground(90);
$this->drawToken();
#$this->drawWave();
#$this->drawLines(16);
}
private function drawBackground($opacity) {
// create true color overlay image:
$overlay_src = imagecreatefrompng('images/captcha/captchabg'.rand(0,1).'.png');
if((bool)rand(0,1)) $overlay_src = imagerotate($overlay_src, 180, 0);
$overlay_w = ImageSX($overlay_src);
$overlay_h = ImageSY($overlay_src);
// copy and merge the overlay image and the canvas image:
imagecopymerge($this->captcha, $overlay_src, 0,0,0,0, $overlay_w, $overlay_h, $opacity);
}
private function drawToken() {
$x= 15;
for($i = 0; $i < $this->captchaLength; $i++) {
$char = $this->charset{rand(0, strlen($this->charset) - 1)};
//for Session
$this->captchaCode .= $char;
$fontColor = imagecolorallocate($this->captcha, rand(0, 100), rand(0, 100), rand(0, 199)); // einen zufälligen Farbwert definieren
$currentCharFont = $this->captchaFonts[rand(0, count($this->captchaFonts) - 1)]; // einen zufälligen Font aus der Fontliste FONTS auswählen
$y = 30 + rand(0, 10); // die y-Koordinate mit einem Mindestabstand plus einem zufälligen Wert festlegen
$angle = rand(0, 23); // ein zufälliger Winkel zwischen 0 und 30 Grad
imagettftext($this->captcha, $this->fontSize, $angle, $x, $y, $fontColor, $currentCharFont, $char);
$dim = imagettfbbox($this->fontSize, $angle, $currentCharFont, $char); // ermittelt den Platzverbrauch des Zeichens
$x += $dim[4] + abs($dim[6]) + 10; // Versucht aus den zuvor ermittelten Werten einen geeigneten Zeichenabstand zu ermitteln
}
}
private function drawLines($opacity) {
$T1 = 20;
$T2 = 30;
$myImage = @imagecreatetruecolor($this->imageWidth, $this->imageHeight);
$backgroundColor = imagecolorallocate($myImage, 255, 255, 255);
imagefill($myImage, 0, 0, $backgroundColor);
imagesetthickness($myImage, 2);
$poly_color = imagecolorallocate($myImage, 0, 0, 0);
//calculate x-value and y-value point by point
$points = array();
for ($i=0; $i<1000; $i=$i+1)
{
//define curve's function
$x = $this->imageWidth/2*cos($i/$T1); //define x-value
$y = $this->imageHeight/2*sin($i/$T2);//define y-value
//move the coordinate, append a point's x-value and y-value
$points[] = $this->imageWidth/2+$x; //x-value
$points[] = $this->imageHeight/2-$y; //y-value
}
//count points
$totalPoints = count($points)/2;
for ($i=0; $i<$totalPoints-1; $i++)
{
imageLine($myImage, $points[2*$i], $points[1+2*$i], $points[2+2*$i], $points[3+2*$i], $poly_color);
}
imagecopymerge($this->captcha, $myImage, 0,0,0,0, $this->imageWidth, $this->imageHeight,$opacity);
}
/*private function drawWave() {
$stauchung = mt_rand(0,100)/400+0.10;
$Grafikalt = $Grafik;
$Grafik = $Grafikhilf;
for ($i=1;$i<=65;$i++){
imagecopy($this->captcha, $this->captcha, round((sin($i*$stauchung)*2))+3, $i, 1, $i, 230,1);
}
}*/
}
?>
Zuletzt bearbeitet: