PHP oturum sorun-

0 Cevap php

Ben captcha görüntü oluşturmak için bir yardımcı işlev çağıran bir Joomla bileşeni var. Sh404 devre dışı olduğunda her şey gayet iyi çalışıyor, ama sh404 etkin olduğunda size 'Geçersiz CAPTCHA' mesajı alıyorum formu gönderdiğinizde güvenlik görüntü için oturum değişken böylece doğru ayarlı değil. Komik şey başka 5-6 kez göndermek varsa, ince doğrular ve gönderir olduğunu. Ben aklınıza gelebilecek hemen her şeyi denedim - Ben oturum değişkeni ve teslim doğrulama kodunu yankı zaman oturum arkasında bir adım olduğunu görünür - örneğin:

Ben oturum değişkeni için boş bir değer elde - Ben formu ilk kez göndermek ve oturumu değişken ve sunulan kod echo oturum değişken zamanlı ayarlı değil gibi görünüyor. Sonra tekrar formu göndermek ve oturumu değişken önceki captcha image değeridir. İşte captcha'yı oluşturur ve doğrular kod. Teşekkürler!

//Generate Captcha image link
function Captchalink($capid = ''){
    return 'index.php?option=com_mycomponent&view=home&task=newCaptcha&capid='.$capid;
}

function generateCode($characters) {
    /* list all possible characters, similar looking characters and vowels have been removed */
    $possible   = '23456789bcdfghjkmnpqrstvwxyz';
    $code       = '';
    $i          = 0;
    while ($i < $characters) {
        $code .= substr($possible, mt_rand(0, strlen($possible)-1), 1);
        $i++;
    }
    return $code;
}

function CaptchaSecurityImages($capid = '') {

    $font       = dirname(__FILE__).DS."monofont.ttf";
    $width      = 90;
    $height     = 30;
    $characters = 6;
    $session    =& JFactory::getSession();

    //Clean buffers
    while (ob_get_level()) {
       ob_end_clean();
    }

    // start output buffering
    if (ob_get_length() === false) {
       ob_start();
    }
    $code = mycomponentHTML::generateCode($characters);

    /* font size will be 75% of the image height */
    $font_size          = $height * 0.75;
    $image              = @imagecreate($width, $height) or die('Cannot initialize new GD image stream');

    /* set the colors */
    $background_color   = imagecolorallocate($image, 255, 255, 255);
    $text_color         = imagecolorallocate($image, 20, 40, 100);
    $noise_color        = imagecolorallocate($image, 100, 120, 180);

    /* generate random dots in background */
    for( $i=0; $i<($width*$height)/3; $i++ ) {
        imagefilledellipse($image, mt_rand(0,$width), mt_rand(0,$height), 1, 1, $noise_color);
    }

    /* generate random lines in background */
    for( $i=0; $i<($width*$height)/150; $i++ ) {
        imageline($image, mt_rand(0,$width), mt_rand(0,$height), mt_rand(0,$width), mt_rand(0,$height), $noise_color);
    }

    /* create textbox and add text */
    $textbox = imagettfbbox($font_size, 0, $font, $code)  or die('Error in imagettfbbox function');
    $x = ($width - $textbox[4])/2;
    $y = ($height - $textbox[5])/2;
    imagettftext($image, $font_size, 0, $x, $y, $text_color, $font , $code) or die('Error in imagettftext function');

    /* output captcha image to browser */
    header('Content-Type: image/jpeg');
    imagejpeg($image);
    imagedestroy($image);

    /* set session variable for newly created code */
    $session->set('security_code_'.$capid, md5($code));

    ob_end_flush();
    die();

}

function CaptchaValidate($capid = ''){
    $session    =& JFactory::getSession();
    if( $session->get('security_code_'.$capid) == md5(JRequest::getVar('security_code_'.$capid)) ) {
        $session->clear('security_code_'.$capid);
        return true;
    }else{
        return false;
    }
}

0 Cevap