2011-01-25 6 views
1

일련의 3 페이지에서 사용되는 데이터를 보관하기 위해 codeigniter 세션 라이브러리를 사용하고 있으며 이상한 동작이 발생합니다. 내 세션 변수는 그대로 있지만 값은 사라집니다. 낯선 사람 : 세션 데이터에 직렬화 된 배열을 저장하려고하는데 배열의 첫 번째 항목이 다른 변수에 저장됩니다.codeigniter 세션 문제 - 일부 세션 정보가 고집하지 않음

다음 페이지로 이동할 수있는 시리즈의 첫 번째 페이지부터 시작하는 링크를 첨부했습니다. 두 페이지의 상단에 user_session 데이터를 인쇄했습니다 (세 번째 페이지는 아직 설정되지 않았습니다). 내가 로그인 데이터를 저장하는 세션을 사용하고 있는데, 예를 들어

http://playmatics.com/nypl/site/index.php/member_area/quest/accept_quest/12

세션, 다른 곳에서 일을하고 잘 작동합니다. 다른 사람이 말했듯이

내가

//CONTROLLER: 
    function accept_quest() { 
     $assoc_quest_id = end($this->uri->segments); 

     if(!isset($quest_id)) { 
      redirect('member_area/quest'); 
      //SEND A MESSAGE: NO QUEST STARTED 
     } 

     $quest_rows = $this->quest_model->get_quest_with_images($assoc_quest_id); 
     $quest = current($quest_rows); 
     $images = $this->pull_out_images($quest_rows); 

     //the data array is used both in the session, 
     //to pass values over to the next function in the quest chain 
     //and in the template 
     $data = array(); 
     $data['quest_id'] = $assoc_quest_id; 
     $data['instruction_text'] = $quest->instructions; 
     $data['quest_title'] = $quest->name; 
     $data['quest_time_limit'] = $quest->time_limit; 
     $data['points_awarded'] = $quest->points_availible; 
     $data['quest_images'] = serialize($images); 

     //save data in a flash session to be used in the next function call in the quest chain: quest_action 
     $this->session->set_userdata($data); 
     print_r($this->session->all_userdata()); 


     //the following data aren't needed in the session so they are added to the data array after the session has been set 
     $data['annotation_text'] = $quest->note;   
     $data['main_content'] = 'quests/quest_desc'; 
     $this->load->view('includes/template', $data); 
} 


function quest_action() { 
    print_r($this->session->all_userdata()); 

    $quest_id = $this->session->userdata('quest_id'); 
    echo "the quest id is: $quest_id"; 
    if(!isset($quest_id)) { 
     redirect('member_area/quest'); 
     //SEND A MESSAGE: NO QUEST STARTED 
    } 

    $data['quest_id'] = $quest_id; 
    $data['quest_title'] = $this->session->userdata('quest_title'); 
    $data['quest_images'] = $this->session->userdata('images'); 
    $data['instruction_text'] = $this->session->userdata('instructions'); 
    $data['quest_time_limit'] = $this->session->userdata('quest_time_limit'); 

    $data['main_content'] = 'quests/quest_action'; 
    $this->load->view('includes/template', $data);     
} 

//VIEW 
    //quest_desc: 
<h1><?= $quest_title ?></h1> 
    <div id="quest_elements"> 
     <figure> 
     <? foreach(unserialize($quest_images) as $image): ?> 
      <img class="media" src="<?= $image ?>" alt="<?= $quest_title ?> image"/> 
     <? endforeach; ?> 
      <figcaption>annotation: <?= $annotation_text ?></figcaption> 
     </figure> 
     <?= anchor("member_area/quest/quest_action", "Start Quest", array('title' => 'start quest')); ?> 
    </div><!-- end quest_elements --> 


    //quest_action: 
<h1><?= $quest_title ?></h1> 
    <div id="quest_elements"> 
     <figure> 
     <? foreach(unserialize($quest_images) as $image): ?> 
      <img class="media" src="<?= $image ?>" alt="<?= $quest_title ?> image"/> 
     <? endforeach; ?> 
      <figcaption>instructions: <?= $instruction_text ?></figcaption> 
     </figure> 
    <div id="timer"> 
     <?= $quest_time_limit; ?> 
    </div> 
    <?= anchor("#start_timer", "Start Timer", array('title' => 'start quest timer')); ?> 
</div> 
+0

CI는 기본적으로 쿠키를 사용하여 세션을 저장합니다. 쿠키 크기 제한에 부딪치지 않습니까? –

+0

또한 세션 데이터를 암호화하는 경우 데이터 크기가 커지고 제한 속도가 더욱 빨라질 수 있습니다. – k00k

+0

아, 그게 아마도 문제입니다. 감사! – JoeM05

답변

3

쿠키 크기 한도를 맞추려면 CodeIgniter의 네이티브 Database Sessions class으로 전환하는 것이 좋습니다. 이렇게하면 데이터베이스에 세션 정보를 저장하고 쿠키 크기 제한을 효과적으로 제거 할 수 있으므로 ci_sessions 데이터베이스의 user_data 필드의 크기로 제한됩니다.

위의 링크를 따라 데이터베이스 세션 활용에 대한 섹션이 맨 아래에 표시되어 적절한 DB 스키마와 데이터베이스 세션으로의 구성 전환을 제공합니다.