iamjonesy
iamjonesy

Reputation: 25132

Codeigniter session issues in Internet Explorer

I have a CI application that uses the CI session class. Here's the process I'm having trouble with:

  1. Users loads page
  2. Ajax request to get record from DB
  3. Set userdata variable with that record's ID & do various DB stuff
  4. User refreshes the page
  5. Ajax request to get record from DB based on the session variable of the previous record (same record can not be passed back twice in a row)
  6. re-set userdata variable to new record's ID

etc. etc.

This works perfectly in chrome and FF. But obviously when I come to test in IE - doesn't work.

The ajax request is executed and the first record is retreived. At this point the session variable has been set. User refreshes but the same record remains.

At this point if I clear session cookies and refresh the new record is retrieved.

I've tried changing:

$config['sess_cookie_name']     = 'ci_session';

to

$config['sess_cookie_name']     = 'cisession';

Like I saw in another post but no luck. Also tried using DB for session storage but still no luck.

Here is the problem page: http://givestream.co.uk/stream

Load this in chrome or FF and either refresh or hit the 'Next' button and you'll see it retrieves a new charity. Try this in IE and it doesn't work unless you clear session cookies.

JS function to get record:

function get_matches(){
    var charity;
    var user_total;
    jQuery.get("/stream/get_charity/", function(data){

        charity = data.charity;
        user_total = charity.user_totals;

        /** CHANGE URL **/

        if (history.pushState) {
            window.history.pushState("object or string", "Title", "/stream/"+charity.slug);
        }

        /*****************/

        // can user accept?
        if(charity.can_donate == 0){
            // No
            jQuery('.alert-message').show();
        } else{
            jQuery('.alert-message').hide();
        }

        // Charity Binding
        jQuery('p#char_modal_description').html(charity.description);
        jQuery('.char_more_link').attr('id', charity.id);
        jQuery('h1#char_name').html(charity.char_name);
        jQuery('h2#char_modal_header').html(charity.char_name);
        jQuery('p#char_desc').html(charity.description);
        jQuery('#website').html('<label>Website</label><a href="'+charity.website+'" style="color:#08C;" target="_blank">'+charity.website+'</a>');
        jQuery('#char_total').text('\u00A3'+charity.total);
        jQuery('#donors').html(charity.recent_donors);
        jQuery('#fans').html(charity.recent_fans);

        if (typeof user_total !== 'undefined') {
            jQuery('#total_char_month').text('\u00A3'+user_total.total_char_month);
            jQuery('#total_char_alltime').text('\u00A3'+user_total.total_char_alltime);
            var has_user_seen_stream_notice = user_total.has_user_seen_stream_notice;

            if(has_user_seen_stream_notice == false){
                jQuery('#stream_help').show();
            } 
        } else{
            jQuery('#total_char_month').text('\u00A3'+0);
            jQuery('#total_char_alltime').text('\u00A3'+0);
        }

        /** TWITTER SHARE BUTTON CHANGE URL **/

        var twitter = '<a href="https://twitter.com/share" class="twitter-share-button" data-url="http://givestream.co.uk/stream/'+charity.slug+'" data-via="givestreamuk" data-hashtags="socialgiving">Tweet</a>';
        jQuery('#twitter_share').html(twitter);

        var jstext = '!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src="//platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");';

        var script   = document.createElement("script");
        script.type  = "text/javascript";
        script.text  = jstext;
        jQuery('#twitter_share').append(script);

        // *************************************//


        /** FACEBOOK SHARE WIDGET **/

            var fb = '<iframe src="//www.facebook.com/plugins/like.php?href=http://givestream.co.uk/stream/'+charity.slug+'&amp;send=false&amp;layout=standard&amp;width=280&amp;show_faces=false&amp;action=like&amp;colorscheme=light&amp;font&amp;height=35&amp;appId=119083868224729" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:280px; height:35px;" allowTransparency="true"></iframe>';
            jQuery('#fb_share').html(fb);


        // ***********************//


        jQuery('#char_website').html(charity.website);

        jQuery('#sectors').html('<label>Tags</label>'+charity.sectors);
        jQuery('#permalink').val('http://givestre.am/stream/'+charity.slug);

        jQuery('#refresh').activity(false);

        get_charity_gallery();
        get_charity_shouts();

    }, 'json');

    return;
}

Upvotes: 1

Views: 7234

Answers (4)

RamiroRS
RamiroRS

Reputation: 461

Try to set $config['sess_match_useragent'] = FALSE;

Upvotes: 2

illusionicea
illusionicea

Reputation: 31

Try this by setting sess_expire_on_close = true. I solved mine with this setting at config.

Upvotes: 3

iamjonesy
iamjonesy

Reputation: 25132

Fixed!

It wasn't a ci_session issue it would seem.

I dug a bit deeper and added

log_message('info', 'queried!-'.$_SERVER['HTTP_USER_AGENT']);

Into the controller that does the json response to see if the ajax request was actually reaching the controller and it turned out none of the IE ajax get requests actually made it to the controller.

Turns out that even though the IE network inspector acknowleged the get request it was actually using cached ajax responses.

I added

jQuery.ajaxSetup ({
    // Disable caching of AJAX responses
    cache: false
});

To the top of the js script and boom. sorted.

Thanks to @Laurencei for the help though!

Upvotes: 5

Laurence
Laurence

Reputation: 60058

Ignore the comment above - this is a CI issue, not a JS issue.

Firstly, IE sessions might also fail if “cookie_domain” is not correctly set - especially if it is left blank. All other browsers will continue to work, but not IE.

Secondly - try this solution: http://codeigniter.com/forums/viewthread/203821/

Thirdly - use this solution (which I use - works REALLY well): http://codeigniter.com/forums/viewthread/170123/ (about half way down - the MY_Session file posted by WanWizard

Upvotes: 1

Related Questions