<i id='fZVKd'><tr id='fZVKd'><dt id='fZVKd'><q id='fZVKd'><span id='fZVKd'><b id='fZVKd'><form id='fZVKd'><ins id='fZVKd'></ins><ul id='fZVKd'></ul><sub id='fZVKd'></sub></form><legend id='fZVKd'></legend><bdo id='fZVKd'><pre id='fZVKd'><center id='fZVKd'></center></pre></bdo></b><th id='fZVKd'></th></span></q></dt></tr></i><div id='fZVKd'><tfoot id='fZVKd'></tfoot><dl id='fZVKd'><fieldset id='fZVKd'></fieldset></dl></div>
    1. <tfoot id='fZVKd'></tfoot>

      • <bdo id='fZVKd'></bdo><ul id='fZVKd'></ul>

      <small id='fZVKd'></small><noframes id='fZVKd'>

    2. <legend id='fZVKd'><style id='fZVKd'><dir id='fZVKd'><q id='fZVKd'></q></dir></style></legend>
    3. Joomla 2.5 JFactory::getSession();似乎在 Firefox 中缓存

      Joomla 2.5 JFactory::getSession(); seems to be caching in firefox(Joomla 2.5 JFactory::getSession();似乎在 Firefox 中缓存)
        <tbody id='l4j4W'></tbody>

          <tfoot id='l4j4W'></tfoot>

            <legend id='l4j4W'><style id='l4j4W'><dir id='l4j4W'><q id='l4j4W'></q></dir></style></legend>
                <bdo id='l4j4W'></bdo><ul id='l4j4W'></ul>

              • <small id='l4j4W'></small><noframes id='l4j4W'>

                <i id='l4j4W'><tr id='l4j4W'><dt id='l4j4W'><q id='l4j4W'><span id='l4j4W'><b id='l4j4W'><form id='l4j4W'><ins id='l4j4W'></ins><ul id='l4j4W'></ul><sub id='l4j4W'></sub></form><legend id='l4j4W'></legend><bdo id='l4j4W'><pre id='l4j4W'><center id='l4j4W'></center></pre></bdo></b><th id='l4j4W'></th></span></q></dt></tr></i><div id='l4j4W'><tfoot id='l4j4W'></tfoot><dl id='l4j4W'><fieldset id='l4j4W'></fieldset></dl></div>

                本文介绍了Joomla 2.5 JFactory::getSession();似乎在 Firefox 中缓存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我在包含目录中有一个 php 文件.它的可用性是显示验证码图像.在那个文件中,我设置了一个这样的会话变量:

                I have a php file in includes directory. It's usability is to display a captcha Image. In that file I set a session variable like this:

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

                这个会话变量是从一个图像 src 中设置的,该图像从控制器调用该方法.

                This Session variable is set from an image src that calls that method from a controller.

                然后我调用控制器来检查设置的会话(此方法是使用 iframe 中的 ajax 触发的)并且在该方法中我执行此操作

                Then I call a controller to check that session that was set (this method is trigerd with ajax from an iframe) and in that method I do this

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

                第一次结果和预期一样,设置的代码和一个随机数.如果我刷新该页面,验证码图像将使用新代码重置并显示.但是当我再次触发检查事件时,我得到了带有新随机数的先前代码.rand() 有证据表明 JFactory::getSession(); 被缓存了,因为我得到了新的随机数,但之前的代码相同,而不是新的到.所以并不是 ajax 在这里缓存了一些东西.

                The result is as expected the first time, the code that was set and a random number. If I refresh that page the captcha image gets reset with a new code and gets displayed. But when I triger the check event again, I get the previous code with a new random number. That rand() there is a proof that JFactory::getSession(); is cached because I get the new random number but the same previous code and not the new as supposed to. So it's not that ajax that is caching something here.

                如何避免 JFactory::getSession(); 从 Firefox 缓存?这只发生在 Firefox 中.Internet Explorer 和 chrome 似乎可以正确显示会话代码.如果我清除 firefox cash 并刷新页面,它仍然不起作用.就像它被永远缓存一样.如果我关闭 Firefox 并再次打开它,那么一切似乎都像第一次一样工作,但是我又遇到了同样的问题.

                How can I avoid JFactory::getSession(); geting cached from firefox? This happens only in firefox. Internet explorer and chrome seem to display the session code correctly. If I clear firefox cash and refresh the page it still doesn't work. It's like it's cached for ever. If I close firefox and open it again, then everything seems to work as the first time, but then I have the same issue again.

                这是生成验证码的代码

                <?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调用的代码

                And here is the code that is called by the 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 );
                            });
                

                请帮忙

                推荐答案

                我遇到了同样的问题,但在设置新会话变量之前调用 clear 方法解决了这个问题.

                I had the same problem, but calling the clear method before setting a new session variable fixed the problem.

                    $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);
                

                即使是您第一次声明会话变量也能正常工作.

                It works even if is the first time you are declaring a session variable.

                这篇关于Joomla 2.5 JFactory::getSession();似乎在 Firefox 中缓存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                相关文档推荐

                Is Joomla 2.5 much faster than Joomla 1.5 Querywise(Joomla 2.5 比 Joomla 1.5 Querywise 快得多吗)
                How to share Joomla login session from one joomla website to one ASP.Net MVC website(如何将 Joomla 登录会话从一个 joomla 网站共享到一个 ASP.Net MVC 网站)
                htaccess redirect root to subdirectory but allow index.php in root AND query strings to function(htaccess 将根重定向到子目录,但允许根和查询字符串中的 index.php 起作用)
                Joomla include database functions(Joomla 包含数据库功能)
                nl2br() not working when displaying SQL results(显示 SQL 结果时 nl2br() 不起作用)
                Joomla to Static HTML website(Joomla 到静态 HTML 网站)

                  <tbody id='gckWw'></tbody>

                    <i id='gckWw'><tr id='gckWw'><dt id='gckWw'><q id='gckWw'><span id='gckWw'><b id='gckWw'><form id='gckWw'><ins id='gckWw'></ins><ul id='gckWw'></ul><sub id='gckWw'></sub></form><legend id='gckWw'></legend><bdo id='gckWw'><pre id='gckWw'><center id='gckWw'></center></pre></bdo></b><th id='gckWw'></th></span></q></dt></tr></i><div id='gckWw'><tfoot id='gckWw'></tfoot><dl id='gckWw'><fieldset id='gckWw'></fieldset></dl></div>

                        • <bdo id='gckWw'></bdo><ul id='gckWw'></ul>
                        • <legend id='gckWw'><style id='gckWw'><dir id='gckWw'><q id='gckWw'></q></dir></style></legend>

                          <small id='gckWw'></small><noframes id='gckWw'>

                          <tfoot id='gckWw'></tfoot>