huhu liebe Leute,
Ich habe ein merkwürdiges Problem und weiß einfach nich woran es liegt
ich generiere ein captcha klappt alles super, zeige es auf der seite an und habe da einen link gemacht auf den man klicken soll wenn man das captcha nicht erkennt, dieses wird per ajax neu geladen und die captcha.php neu ausgefüht. das merkwürdige ist bei dem klicken auf den link macht er es manchmal, manchmal aber passiert garnix nun weiß ich nicht ob es am php code des captchas lkieght das es einfach zu ineffizient ist oder ob ich einen fehler in meinem javascript habe ich bitte daher um eure hilfe.
Quelltext:
erst das des captchas:
nun der javascript
ich würde mich auch um optimierungen freuen
mit freundlichen grüßen Jörg
Ich habe ein merkwürdiges Problem und weiß einfach nich woran es liegt
ich generiere ein captcha klappt alles super, zeige es auf der seite an und habe da einen link gemacht auf den man klicken soll wenn man das captcha nicht erkennt, dieses wird per ajax neu geladen und die captcha.php neu ausgefüht. das merkwürdige ist bei dem klicken auf den link macht er es manchmal, manchmal aber passiert garnix nun weiß ich nicht ob es am php code des captchas lkieght das es einfach zu ineffizient ist oder ob ich einen fehler in meinem javascript habe ich bitte daher um eure hilfe.
Quelltext:
erst das des captchas:
PHP-Code:
/* Create Capctha */
$str_array = array("A", "C", "F", "H", "J", "L", "N", "P", "S", "U", "V", "X", "Z", "B", "D", "F", "H", "J", "L", "N", "P", "Q", "S", "U", "W", "Y", 1, 2, 3, 4, 5, 6, 7, 8, 9);
$ttfarr = array();
/*ttf array dynamisch generieren*/
$ordner = dirname(__FILE__)."/../library/ttf/";
$handle = opendir($ordner);
while ($file = readdir($handle))
if($file != "." && $file != ".." && !is_dir($ordner."/".$file))
$ttfarr[] = $file;
closedir($handle);
$char_seq = "";
for($i = 0;$i < 5;$i++) {
$int = (int)rand(0, count($str_array)-1);
$char_seq .= $str_array[$int];
}
$num_chars = 4;
$width = 250;
$height = 100;
$img = imagecreatetruecolor($width , $height);
imagealphablending($img, 1);
imagecolortransparent($img);
// generate background of randomly built ellipses
for ($i = 1; $i <= 55; $i++) {
$r = round(rand(0, 100));
$g = round(rand(0, 100));
$b = round(rand(0, 100));
$color = imagecolorallocate($img, $r, $g, $b);
imagefilledellipse($img, round(rand(0, $width)), round(rand(0, $height)), round(rand(0, $width / 16)), round(rand(0, $height / 4)), $color);
}
$start_x = round($width / $num_chars);
$max_font_size = $start_x;
$start_x = round(0.5 * $start_x);
$max_x_ofs = round($max_font_size * 0.9);
// set each letter with random angle, size and color
for($i=0;$i<=5;$i++)
{
$r = (int)rand(127, 255);
$g = (int)rand(127, 255);
$b = (int)rand(127, 255);
$y_pos = ($height / 2) + (int)rand(5, 20);
$fontsize = (int)rand(23, $max_font_size);
$color = imagecolorallocate($img, $r, $g, $b);
$presign = (int)rand(0, 1);
$angle = round(rand(0, 25));
if ($presign == true) $angle = -1 * $angle;
$randttf = round(rand(0, count($ttfarr)-1));
$ttf = $ordner . $ttfarr[$randttf];
$x = $start_x + $i * $max_x_ofs+7;
ImageTTFText($img, $fontsize, $angle,$x, $y_pos, $color,$ttf, substr($char_seq, $i, 1));
}
// create image file
imagejpeg($img,dirname(__FILE__)."/../library/images/captcha.jpg",65);
flush();
imagedestroy($img);
/* Captcha End */
Code:
function refreshCaptcha()
{
//globale Instanz von XMLHttpRequest
var xmlHttp = false;
//XMLHttpRequest-Instanz erstellen
//... für Internet Explorer
try {
xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch(e) {
try {
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
} catch(e) {
xmlHttp = false;
}
}
//... für Mozilla, Opera, Safari usw.
if (!xmlHttp && typeof XMLHttpRequest != 'undefined') {
xmlHttp = new XMLHttpRequest();
}
if (xmlHttp) {
xmlHttp.open('GET', './libs/captcha.php?param=1', true);
xmlHttp.onreadystatechange = function () {
if (xmlHttp.readyState == 4) {
captcha = new Image();
captcha.src = "./library/images/captcha.jpg";
document.getElementById("captcha").src = captcha.src;
//document.getElementById("asb_content").innerHTML = xmlHttp.responseText;
}
};
xmlHttp.send(null);
}
}
mit freundlichen grüßen Jörg

Kommentar