Welcome Guest, Not a member yet? Register   Sign In
Session Problem : FireFox works 100%, IE Not working
#1

[eluser]helphelp[/eluser]
I have encounter a wired problem.

I use the ezauth model as my login system. Everything is working fine.

Then i try to use squploader to upload file
i follow this wiki
http://codeigniter.com/wiki/Category:AJAXForm/

to change setting.

**user require to do login before upload so session data store all user data before they come to upload page ****

The problem is that whenever i click on the flash upload and wait for it finish, my IE session data will be gone. But in firefox, all session data are fine.

i have tried to stay on the upload page (don't do upload) and call next controller, Both IE and Firefox still show my session data. As long as i run squploader ( Flash uploader ) and start do upload , IE will lose all my session data BUT firefox is still OK.

thanks for help
#2

[eluser]thurting[/eluser]
native sessions, CI sessions (cookies), or CI sessions (DB)?
#3

[eluser]helphelp[/eluser]
at first i use CI session library, got this problem

then i change to OBSession version 2.0.1 by Oscar Bajner . still the same.

i don't know why the flash object will end my session.

Thanks

edit no DB,
#4

[eluser]Rick Jolly[/eluser]
I'm not sure what the issue is, but it could be related to caching. CI and OBSession don't use php native sessions, and last time I checked they didn't send the cache control headers that native sessions do. Check this out for the difference:http://ellislab.com/forums/viewthread/52129/#258003

If all else fails, you might want to try native sessions. There is a native session library in the wiki that supports flash data.
#5

[eluser]helphelp[/eluser]
i have made up a simple sample. i still have that error in IE. IE will lose all session data after i do the flash upload.

here are the code.


the controller
Code:
<?php
class Upload extends Controller {

    function Upload()
    {
        parent::Controller();
        $this->load->helper(array('form', 'url'));
    }
    function index()
    {
        $this->load->view('demo');
    }

    function first()
    {
        $this->session->set_userdata('first', '1');
        $this->session->set_userdata('second', '2');
        $this->load->view('first');
    }
    
    function third()
    {
        $this->load->view('third');
    }
        
        
    function flash(){

    $uploadDir = './uploads/';
    @$uploadFile = $uploadDir . basename($_FILES['Filedata']['name']);
    
    if ($_POST['submit'] != '') {

        if ($this->uri->segment(3,0)) {

            if (move_uploaded_file ($_FILES[0]['tmp_name'], $uploadFile)) {

            } else {
            }

        } else {
            $html_body = '<h1>Form posted!</h1><pre>';
            $html_body .= print_r($_POST, true);
            $html_body .= '</pre>';
        }
        echo ($html_body);
    } else {
        
        if ($this->uri->segment(3,1)){

            if ($_FILES['Filedata']['name']) {
                if (move_uploaded_file ($_FILES['Filedata']['tmp_name'], $uploadFile)) {

                    return $uploadFile;
                }
            } else {
                if ($_FILES['Filedata']['error']) {
                    return $_FILES['Filedata']['error'];
                }
            }
        }
    }
    }
}
?&gt;
the "first" view
Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
&lt;html lang="en"&gt;
&lt;head&gt;
&lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8" /&gt;
&lt;/head&gt;
&lt;body&gt;

<p>First session data:&lt;?=$this->session->userdata('first');?&gt;</p>
<p>Second session data:&lt;?=$this->session->userdata('second');?&gt;</p>
<a href="http://localhost/index.php/upload/">click here to upload</a>

&lt;/body&gt;
&lt;/html&gt;
The demo view
Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
&lt;html lang="en"&gt;
&lt;head&gt;
&lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8" /&gt;
&lt;title&gt;jqUploader demo&lt;/title&gt;




$(document).ready(function(){
    $("#example1").jqUploader({
    
    src: "http://localhost/js/jqUploader.swf",
    background:"FFFFFF",
    barColor:"FF0000",
    allowedExt:"*.avi; *.jpg; *.jpeg; *.png",
    hideSubmit: true})
});

&lt;/head&gt;
&lt;body&gt;
<div id="page">
  &lt;form enctype="multipart/form-data" action="http://localhost/index.php/upload/flash" method="POST" class="a_form"&gt;

    <fieldset>
    <legend>Flie</legend>
    <ol>
      <li id="example1">
        <label for="example1_field">Choose a file to upload: </label>
        &lt;input name="MAX_FILE_SIZE" value="1048576" type="hidden" /&gt;
        &lt;input name="myFile"  id="example1_field"  type="file" /&gt;
      </li>
    </ol>
    </fieldset>
    &lt;input type="submit" name="submit" value="Send" /&gt;
  &lt;/form&gt;
&lt;/body&gt;
&lt;/html&gt;
The "thrid" view
Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
&lt;html lang="en"&gt;
&lt;head&gt;
&lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8" /&gt;
&lt;/head&gt;
&lt;body&gt;
<p>here is the first:&lt;?=$this->session->userdata('first');?&gt;</p>
<p>Here is the second:&lt;?=$this->session->userdata('second');?&gt;</p>
<a href="http://localhost/index.php/upload/">click here to upload</a>
&lt;/body&gt;
&lt;/html&gt;
#6

[eluser]helphelp[/eluser]
the jpuploader.js

Code:
jQuery.fn.jqUploader = function(options) {
    return this.each(function(index) {
        var $this = jQuery(this);
        // fetch label value if any, otherwise set a default one
        var $thisForm =  $this.parents("form");
        var $thisInput = $("input[@type='file']",$this);
        var $thisLabel = $("label",$this);
        var containerId = $this.attr("id") || 'jqUploader-'+index;
        var startMessage = ($thisLabel.text() =='') ? 'Please select a file' : $thisLabel.text();
        // get form action attribute value as upload script, appending to it a variable telling the script that this is an upload only functionality
        var actionURL = $thisForm.attr("action");
        actionURL = actionURL+'/1';
        // check if max file size is set in html form
        var maxFileSize = $("input[@name='MAX_FILE_SIZE']", $(this.form)).val();
        var opts = jQuery.extend({
                width:320,
                height:85,
                version: 8, // version 8+ of flash player required to run jqUploader
                background: 'FFFFFF', // background color of flash file
                src:    'jqUploader.swf',
                uploadScript:     actionURL,
                afterScript:      null, // if this is empty, jqUploader will replace the upload swf by a hidden input element
                varName:            $thisInput.attr("name"),  //this holds the variable name of the file input field in your html form
                allowedExt:          '*.jpg; *.jpeg; *.png', // allowed extensions
                allowedExtDescr:  'Images (*.jpg; *.jpeg; *.png)',
                params:           {menu:false},
                flashvars:        {},
                hideSubmit:       true,
                barColor:              '0000CC',
                maxFileSize:      maxFileSize,
                startMessage:     startMessage,
                errorSizeMessage: 'File is too big!',
                validFileMessage: 'now click Upload to proceed',
                progressMessage: 'Please wait, uploading ',
                endMessage:    'You\'re all done'
        }, options || {}
        );
        // disable form submit button
        if (opts.hideSubmit==true) {
            $("*[@type='submit']",this.form).hide();
        }
        // THIS WILL BE EXECUTED IN THE USECASE THAT THERE IS NO REDIRECTION TO BE DONE AFTER UPLOAD
        TerminateJQUploader = function(containerId,filename,varname){
            $this= $('#'+containerId).empty();
            $this.text('').append('<span style="color:#00CC00">Upload of <strong>'+filename+'</strong> finished! <a href="http://localhost/index.php/third">Click here to go to order detail page!</a></span>&lt;input name="'+varname+'" type="hidden" id="'+varname+'" value="'+filename+'"/&gt;');
            var myForm = $this.parents("form");
            myForm.submit(function(){return true});
            $("*[@type='submit']",myForm).show();
        }
        var myParams = '';
        for (var p in opts.params){
                myParams += p+'='+opts.params[p]+',';
        }
        myParams = myParams.substring(0, myParams.length-1);
        // this function interfaces with the jquery flash plugin
        jQuery(this).flash(
        {
            src: opts.src,
            width: opts.width,
            height: opts.height,
            id:'movie_player-'+index,
            bgcolor:'#'+opts.background,
            flashvars: {
                containerId: containerId,
                uploadScript: opts.uploadScript,
                afterScript: opts.afterScript,
                allowedExt: opts.allowedExt,
                allowedExtDescr: opts.allowedExtDescr,
                varName :  opts.varName,
                barColor : opts.barColor,
                maxFileSize :opts.maxFileSize,
                startMessage : opts.startMessage,
                errorSizeMessage : opts.errorSizeMessage,
                validFileMessage : opts.validFileMessage,
                progressMessage : opts.progressMessage,
                endMessage: opts.endMessage
            },
            params: myParams
        },
        {
            version: opts.version,
            update: false
        },
            function(htmlOptions){
                var $el = $('<div id="'+containerId+'" class="flash-replaced"><div class="alt">'+this[removed]+'</div></div>');
                     $el.prepend($.fn.flash.transform(htmlOptions));
                     $('div.alt',$el).remove();
                     $(this).after($el).remove();
            }
        );
    });
};

so when i open the both page in IE tab
http://localhost/index.php/upload/first/
http://localhost/index.php/upload/third/

i can see both "1" and "2" output on my page.

then i click the link on "first" page and go to "demo" view to do upload. After it finish, i go to "third" page and refresh "third" page, "1" and "2" are gone. but in firefox, "1" and "2" are still there.

Any CI superhero can save me for this?
Thanks

p.s. i autoload session library in the autoload config
#7

[eluser]helphelp[/eluser]
i test it again,
i notice that the session data lost is when the upload was finish. it is happen when the following script execute.

Code:
// THIS WILL BE EXECUTED IN THE USECASE THAT THERE IS NO REDIRECTION TO BE DONE AFTER UPLOAD
        TerminateJQUploader = function(containerId,filename,varname){
            $this= $('#'+containerId).empty();
            $this.text('').append('<span style="color:#00CC00">Upload of <strong>'+filename+'</strong> finished! <a href="http://localhost/index.php/third">Click here to go to order detail page!</a></span>&lt;input name="'+varname+'" type="hidden" id="'+varname+'" value="'+filename+'"/&gt;');
            var myForm = $this.parents("form");
            myForm.submit(function(){return true});
            $("*[@type='submit']",myForm).show();
        }

thanks
#8

[eluser]Rick Jolly[/eluser]
That's a lot of code. Did you try native sessions or at least add some headers to prevent caching?
#9

[eluser]helphelp[/eluser]
[quote author="Rick Jolly" date="1194701264"]That's a lot of code. Did you try native sessions or at least add some headers to prevent caching?[/quote]

can you please point me some sample how to add headers to prevent caching? This will save me lots of time for searching

Thanks
#10

[eluser]helphelp[/eluser]
Wow, i go to wiki and d/l the naive session libirary and replace it

It work. Now my IE will not lose any sessoin data

Thanks a lot Rick
Thanks




Theme © iAndrew 2016 - Forum software by © MyBB