Hallo,
ich habe eine kleine Refresh Methode mit Jquery erstellt.
Dies klappt auch ganz gut nur zeigt die session mit var_dump etwas anderes als das Bild.
refresh des captcha (auf das Bild klicken):
	Der captcha selber:
	
Das System wo es geladen wird:
register:
	
das template:
	und noch die funktion set_tpl:
	
Warum zeigt das Bild andere Buchstaben/Zahlen wie dei Session?
mfg Marco
					ich habe eine kleine Refresh Methode mit Jquery erstellt.
Dies klappt auch ganz gut nur zeigt die session mit var_dump etwas anderes als das Bild.
refresh des captcha (auf das Bild klicken):
HTML-Code:
	
	$('#captcha').live('click', function(e) {
    $('#captcha').attr('src','../content/index/captcha.php?[B]<?php echo SID;?>[/B]&'+new Date().getTime());
});
PHP-Code:
	
	
<?php
// Session starten
session_start();
// Größe des Bildes
$size_x = 80;
$size_y = 25;
$n = 6;
if($n < 1) {
   $n = mt_rand(16,32); 
}
$a = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
$l = strlen($a) - 1;
for($i = 0; $i < $n; $i++) {
    $s .= substr($a, mt_rand(0, $l), 1);
}
// Erzeuge eine Zufallszahl
$zufallszahl  = $s;
// Zufallszahl der Session-Variablen übergeben
$_SESSION['captcha_code'] = $zufallszahl;
// Erstelle das Bild mit der angegebenen Größe!
$bild = imageCreate($size_x, $size_y);
// Erstelle einen Hintergrund
imageColorAllocate($bild, 142, 142, 142);
// Zufallsfarbe (RGB) erstellen
$farbe1 = mt_rand("0", "140");
$farbe2 = mt_rand("0", "140");
$farbe3 = mt_rand("0", "140");
// Verteile die Farben
$rahmen = imageColorAllocate($bild, 142, 142, 142); // Rahmenfarbe
$farbe  = imageColorAllocate($bild, $farbe1, $farbe2, $farbe3); // Textfarbe
// Hole die Zahlen der Punkte zum Zeichnen
$alle_punkte = ($size_x * $size_y)/15;
// Zeichne viele Punkte mit der selben Farbe des Textes
for ($zaehler = 0; $zaehler < $alle_punkte; $zaehler++) {
 // Erzeuge die Zufallspositionen der Punkte
 $pos_x = mt_rand("0", $size_x);
 $pos_y = mt_rand("0", $size_y);
 // Zeichne die Punkte
 imageSetPixel($bild, $pos_x, $pos_y, $farbe);
};
// Zeichne den Rahmen
imageRectangle($bild, 0, 0, $size_x-1, $size_y-1, $rahmen);
// Koordinaten der Position von der Zufallszahl
$pos_x = 8; // links
$pos_y = 5; // oben
$z1 = substr($zufallszahl, 1, 1);
$z2 = substr($zufallszahl, 2, 1);
$z3 = substr($zufallszahl, 3, 1);
$z4 = substr($zufallszahl, 4, 1);
$z5 = substr($zufallszahl, 5, 1);
$z6 = substr($zufallszahl, 6, 1);
// Zeichne die Zufallszahl
imageString($bild, 5, $pos_x, $pos_y + mt_rand("-6", "6"), $z1, $farbe);
imageString($bild, 5, $pos_x + 12, $pos_y + mt_rand("-6", "6"), $z2, $farbe);
imageString($bild, 5, $pos_x + 24, $pos_y + mt_rand("-6", "6"), $z3, $farbe);
imageString($bild, 5, $pos_x + 36, $pos_y + mt_rand("-6", "6"), $z4, $farbe);
imageString($bild, 5, $pos_x + 48, $pos_y + mt_rand("-6", "6"), $z5,$farbe);
imageString($bild, 5, $pos_x + 60, $pos_y + mt_rand("-6", "6"), $z6, $farbe);
// Sende "browser header"
header("Content-Type: image/png");
// Sende das Bild zum Browser
echo imagePNG($bild);
// Lösche das Bild
imageDestroy($bild);
?>
register:
PHP-Code:
	
	
 <?php
if ($user->getUserName()) {
    echo 'Du bist eingeloggt und kannst dich nicht registieren.';
}
if ('POST' == $_SERVER['REQUEST_METHOD']) {
    if (!isset($_POST['Username'], $_POST['Password'], $_POST['Email'], $_POST['Captcha'], $_POST['formaction'])) {
        echo INVALID_FORM;
        exit;
    }
    if (!is_array($_POST['Password']) OR count($_POST['Password']) != 2) {
        echo INVALID_FORM;
        exit;
    }
    if ($_POST['Password'][0] != $_POST['Password'][1]) {
        echo 'Bitte geben das gleiche Password ein.';
        exit;
    }
    if (($Username = trim($_POST['Username'])) == '' OR ($Password = trim($_POST['Password'][0])) == '' OR ($Email = trim($_POST['Email'])) == '' OR ($Captcha = trim($_POST['Captcha'])) == '') {
        echo EMPTY_FORM;
        exit;
    }
    
    if(($_SESSION['captcha_code'] == 0) OR ($_POST['Captcha'] != $_SESSION['captcha_code'])){
        echo 'Der Captcha ist falsch';
        exit;
    }
    
    if (!preg_match('~\A\S{3,30}\z~', $Username)) {
        echo 'Der Benutzername darf nur aus 3 bis 30 Zeichen bestehen und keine Leerzeichen enthalten.';
        exit;
    }
    $sql = 'SELECT
                ID
            FROM
                user
            WHERE
                username = ?
            LIMIT
                1';
    $stmt = $db->prepare($sql);
    if (!$stmt) {
        echo $db->error;
    }
    $stmt->bind_param('s', $Username);
    $stmt->execute();
    $stmt->store_result();
    if ($stmt->num_rows) {
        echo 'Der Username wird bereits verwendet.';
        exit;
    }
    $stmt->close();
    
    $sql = 'INSERT INTO
                user(username, email)
            VALUES
                (?, ?)';
    $stmt = $db->prepare($sql);
    if (!$stmt) {
        echo $db->error;
    }
    $stmt->bind_param('ss', $Username, $Email);
    if (!$stmt->execute()) {
        echo $stmt->error;
    }
    $UserID = $stmt->insert_id;
    $sql = 'UPDATE
                user
            SET
                password = ?
            WHERE
                ID = ?';
    $stmt = $db->prepare($sql);
    if (!$stmt) {
        echo $db->error;
    }
    $Hash = md5(sha1($UserID).$Password);
    $stmt->bind_param('si', $Hash, $UserID);
    if (!$stmt->execute()) {
        echo $stmt->error;
    }
    $stmt->close();
    echo 'Der Benutzer wurde hinzugefügt. Du kannst dich nun anmelden.';
    exit;
}
$tpl->set_tpl("register");
?>
HTML-Code:
	
	<div class="register_header">Allgemein</div> <form action="" method="post"> <div class="register_body"> <table cellpadding="6" style="margin:0px auto 0px;"> <tr><td width="200">Username*: </td><td><input type="text" name="Username" class="text" /></td></tr> <tr><td>Password*: </td><td><input type="password" name="Password[]" class="text" /></td></tr> <tr><td>Bestätigung*: </td><td><input type="password" name="Password[]" class="text" /></td></tr> <tr><td>Email*: </td><td><input type="text" name="Email" class="text" /></td></tr> <tr><td>Captcha*:</td><td><img src="content/index/captcha.php" onClick="captcha_reload('../content/index/captcha.php');" id="captcha" class="tooltip" title="Klicken um ein neuen Captcha anzuzeigen" /><input type="text" name="Captcha" class="text" maxlength="6" style="width: 50px; text-align:center;" /></td></tr> <tr><td> </td><td></td></tr> <tr><td></td><td><input type="submit" name="formaction" value="Registieren" class="button" /></td></tr> </table> </div> </form> <?php var_dump($_SESSION['captcha_code']); ?>
PHP-Code:
	
	
    function set_tpl ($tpl_name, $tpl_typ = "index") {
        
        if($tpl_typ == "index") {
            $file = $this->index_path_tpl . $tpl_name . ".tpl";
            if(file_exists($file)) {
                $this->get_title();
                return @include_once ($file);
            } else {
                $this->error_handler(TPL, $tpl_name . ".tpl (" . $tpl_typ . ") ist nicht vorhande!");
            }
        
        } elseif($tpl_typ == "user") {
            $file = $this->user_path_tpl . $tpl_name . ".tpl";
            if(file_exists($file)) {
                $this->get_title();
                return @include_once ($file);
            } else {
                $this->error_handler(TPL, $tpl_name . ".tpl (" . $tpl_typ . ") ist nicht vorhande!");
            }
            
        } elseif($tpl_typ == "admin") {
            $file = $this->admin_path_tpl . $tpl_name . ".tpl";
            if(file_exists($file)) {
                $this->get_title();
                return @include_once ($file);
            } else {
                $this->error_handler(TPL, $tpl_name . ".tpl (" . $tpl_typ . ") ist nicht vorhande!");
            }
        
        } else {
            $this->error_handler(TPL, "Kann ". $tpl_name . ".tpl (" . $tpl_typ . ") nicht laden!");
        }
    } 
mfg Marco
 
          
 Moderatorin
 Moderatorin

Kommentar