2012-08-14 3 views
2

나는 includes 디렉토리에 PHP 파일이있다. 유용성은 보안 문자 이미지를 표시하는 것입니다. 해당 파일 은이 같은 세션 변수를 설정 :Joomla! 2.5 JFactory :: getSession(); 파이어 폭스에서 캐싱하는 것 같다

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

이 세션 변수 제어기에서 해당 메소드를 호출하는 화상 src에서 설정된다.

그러면 I (이 방법은 iframe에서 AJAX로 trigerd이다) 설정된 세션을 체크하도록하는 제어기를 호출하는 방법에있어서 I은 처음에 예상되는 바와 같이,이

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

결과 할 , 설정된 코드 및 난수. 해당 페이지를 새로 고침하면 보안 문자 이미지가 새 코드로 재설정되고 표시됩니다. 하지만 체크 이벤트를 다시 실행하면 이전 코드에 새로운 난수가 생깁니다. 그 rand() 거기에 새로운 난수가 있지만 이전의 동일한 코드를 얻었 기 때문에 JFactory::getSession();이 캐쉬된다는 증거가 있습니다. 여기 뭔가를 캐싱하는 것은 아약스가 아닙니다.

JFactory::getSession();을 Firefox에서 캐시하지 않으려면 어떻게해야합니까? 이것은 파이어 폭스에서만 발생합니다. 인터넷 익스플로러와 크롬이 세션 코드를 올바르게 표시하는 것 같습니다. 파이어 폭스 현금을 지우고 페이지를 새로 고치면 여전히 작동하지 않습니다. 그것은 마치 영원히 캐쉬 된 것과 같습니다. 파이어 폭스를 닫고 다시 열면 모든 것이 처음으로 작동하는 것처럼 보이지만 다시 동일한 문제가 발생합니다. 여기

는 아약스

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

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

     die(); 
    } 

를 호출하는 코드를 보안 문자를

<?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 호출

<?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); 
      }); 

에게 있습니다 제발 도와주세요

+2

브라우저에 실제로이 데이터가 없어야하기 때문에 매우 이상한 버그입니다. 모든 세션 데이터는 클라이언트에 세션 ID 만 보내어 서버에 저장됩니다. 내가 생각할 수있는 최선의 방법은'$ session = clear ('security_code')'를 다시 선언 한 후에 그 값에 영향을 주는지 확인하는 것이다. –

+0

수정 프로그램을 찾은 사람이 있습니까? – max4ever

+1

내가 실제로 한 일은 전화를 할 때마다 매개 변수 ID를 추가하는 것입니다. 이것은 내가 어떻게 내 문제를 해결할 수 있었는지입니다. 다음은 그 예입니다 : $ checkCaptchaSecurityCode = JRoute :: _ ('index.php?옵션 = com_virtuemart & view = 참여 & 태스크 = checkCaptchaSecurityCode & tmpl = 구성 요소 & 형식 = 원시 & ver = 1 '); 그리고 전화를 할 때마다 ver을 2로 변경 한 다음 다시 1로 변경합니다. 이것은 내가 세션을 속이게하는 방법입니다. 그러나 이것은 문제를 해결하지 못합니다. 이것은 단지 멍청한 일입니다. – themis

답변

0

당신은 게시합니까?에서 mydomain.com www.mydomain.com에서 언제? 이것은 내가 믿는 새로운 세션을 만들기 위해 joomla를 일으킬 것입니다.

+0

아니요, 문제는 세션을 변경하지 않고 세션을 변경하지 않고 유지하는 것입니다. – themis

2

동일한 문제가 있었지만 새 세션 변수를 설정하기 전에 clear 메서드를 호출하면 문제가 해결되었습니다.

$session = & JFactory::getSession(); 
    /* this way unset data from the session store */ 
    $session->clear('security_code'); 
    /* and now set the new value */ 
    $session->set('security_code', $code); 

처음으로 세션 변수를 선언하는 경우에도 작동합니다.

관련 문제