2012-04-23 63 views
1

我有一個使用CI會話類的CI應用程序。下面是我遇到的麻煩的過程:Internet Explorer中的Codeigniter會話問題

  1. 用戶加載頁面
  2. Ajax請求從數據庫獲取記錄與該記錄的ID &做各種DB的東西
  3. 用戶刷新
  4. 設置用戶數據變量頁
  5. Ajax請求根據前一個記錄的會話變量從DB獲取記錄(同一記錄不能連續傳回兩次)
  6. 將userdata變量重新設置爲新記錄的ID

等等,等等

這工作完全在Chrome和FF。但顯然,當我來測試在IE瀏覽器 - 不起作用。

ajax請求被執行並且第一條記錄被回收。此時會話變量已設置。用戶刷新但仍保留相同的記錄。

此時如果我清除會話cookie並刷新檢索到的新記錄。

我試着改變:

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

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

正如我在另一篇文章,但沒有運氣看到。還嘗試使用數據庫進行會話存儲,但仍然沒有運氣。

這是問題所在頁:http://givestream.co.uk/stream

加載此鉻或FF,要麼刷新或按「下一步」按鈕,你會看到它檢索新的慈善機構。在IE中試試這個,除非你清除會話cookie,否則它不起作用。

JS函數來獲取記錄:

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; 
} 
+1

我相信你知道,CodeIgniter是一個PHP框架。由於PHP是服務器端語言,因此本身不涉及CodeIgniter。相反,這似乎是一個JavaScript或會話問題。向我們展示一些JavaScript。 – kba 2012-04-23 22:01:08

+0

在ci論壇上搜索與IE瀏覽器會話問題的快速搜索會告訴你會話庫確實存在一些問題。大多數人似乎通過更改ci會話配置來解決它。雖然 – iamjonesy 2012-04-23 22:09:28

回答

5

的MY_Session文件固定!

這似乎不是一個ci_session問題。

我挖了一個深一點,並添加

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

成確實JSON響應,看看Ajax請求實際上到達控制器,控制器,它原來沒有IE瀏覽器的AJAX GET請求實際上由它給控制器。

原來,即使IE網絡檢查員確認了獲取請求,它實際上使用了緩存的ajax響應。

我加

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

要JS腳本和繁榮的頂部。排序。

感謝@Laurencei的幫助!

+0

謝謝,這只是幫助我與同樣的問題時間我有。 – Rob 2012-10-19 15:09:26

+0

是的,搜索解決方案的小時後 - 設置jquery ajax,正如你所提到的,最終讓我有些平安:) – graumanoz 2013-08-01 09:55:40

1

忽略上面的評論 - 這是一個CI的問題,而不是一個JS問題。

首先,如果「cookie_domain」未正確設置,IE會話可能也會失敗 - 尤其是如果它留空。所有其他瀏覽器將繼續工作,但不是IE。

其次 - 嘗試這個解決方案: http://codeigniter.com/forums/viewthread/203821/

三 - 使用此解決方案(我用 - 確實很好): http://codeigniter.com/forums/viewthread/170123/ (約降一半 - 發表WanWizard

+0

感謝您的回覆,但我會放些js。我已經有了cooke_domain集。嘗試從第二個解決方案中添加MY_Session類,但沒有運氣。不幸的是,文件WanWizard發佈似乎是一個斷開的鏈接:( – iamjonesy 2012-04-24 09:04:22

+0

我有一個副本在家裏 - 生病發布後,當我回家 – Laurence 2012-04-24 11:08:41

+0

謝謝勞倫斯! – iamjonesy 2012-04-24 15:46:00

3

通過設置sess_expire_on_close = true來嘗試此操作。我在config中用這個設置解決了我的問題。

+0

謝謝,這節省了我的一天。 – AliAwwad 2014-06-24 23:25:50

2

嘗試設置 $ config ['sess_match_useragent'] = FALSE;