2

includesディレクトリにphpファイルがあります。使いやすさは、キャプチャ画像を表示することです。そのファイルで、次のようなセッション変数を設定しました。

$code = codegenerator();
$session =& JFactory::getSession();
$session->set('security_code', $code);

srcこのセッション変数は、コントローラーからそのメソッドを呼び出すイメージから設定されます。

次に、コントローラーを呼び出して、設定されたセッションを確認し (このメソッドは iframe から ajax を使用してトリガーされます)、そのメソッドでこれを行います

$session = JFactory::getSession();
$seccode=$session->get('security_code');
echo $seccode.':'.rand();

結果は、最初は予想どおり、設定されたコードと乱数です。そのページを更新すると、キャプチャ画像が新しいコードでリセットされ、表示されます。しかし、チェック イベントを再度トリガーすると、新しい乱数で以前のコードが取得されます。新しい乱数を取得するが、以前のコードは同じであり、新しいものではないため、キャッシュされたrand()証拠があること。JFactory::getSession();したがって、ここで何かをキャッシュしているのは ajax ではありません。

JFactory::getSession();firefox からキャッシュされないようにするにはどうすればよいですか? これは firefox でのみ発生します。Internet Explorer と chrome は、セッション コードを正しく表示しているようです。Firefox のキャッシュをクリアしてページを更新しても、まだ機能しません。永遠にキャッシュされているようなものです。Firefox を閉じて再度開くと、すべてが最初と同じように機能するように見えますが、同じ問題が再び発生します。

キャプチャを生成するコードは次のとおりです

<?php

defined('_JEXEC') or die('Restricted access');
class CaptchaSecurityImages {

    var $font='monofont.ttf';


    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($width='220',$height='40',$characters='6') {
        $code = $this->generateCode($characters);

        //$font='includes'.DS.'monofont.ttf';
        $font='monofont.ttf';
        $this->font=$font;

        $session =& JFactory::getSession();
        $session->set('security_code', $code);


        /* 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 colours */
        $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, $this->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, $this->font , $code) or die('Error in imagettftext function');
        /* output captcha image to browser */

        header('Content-Type: image/jpeg');
        imagejpeg($image);
        imagedestroy($image);

    }

}
?>

そして、これがajaxによって呼び出されるコードです

public function checkCaptchaSecurityCode(){
        $securitycode = JRequest::getVar('securitycode');           
        $session = JFactory::getSession();
        $seccode=$session->get('security_code');        

        echo $seccode.':'.rand();

        die();
    }   

そしてここにajax呼び出しがあります

<?php $checkCaptchaSecurityCode = JRoute::_('index.php?option=com_virtuemart&view=participate&task=checkCaptchaSecurityCode&tmpl=component&format=raw'); ?>
    jQuery.ajaxSetup({cache: false});
            jQuery.ajax({
                  type: "POST",
                  url: "<?php echo $checkCaptchaSecurityCode ?>",
                  cache: false,
                  data: { securitycode: jQuery("#security_code").val() }
                }).done(function( msg ) {
                  alert( msg );
            });

助けてください

4

2 に答える 2