2015-07-19 98 views
1

我正在使用CodeWarrior和cloudflare,并在登录期间在会话中存储用户值时收到520错误。Codeigniter在使用会话时抛出520错误CloudFlare

下面是登录功能:

function check_login_submit($post_data) { 
     if ($post_data) { 

      $mob = trim($post_data['mob']); 
      $password = trim($post_data['password']); 

      $sql = "Select * from table where phone='$mob' and password='$password'"; 
      $query = $this->db->query($sql); 
      $user = $query->row(); 

      if ($query->num_rows() == 1) { 
      if ($user->status == 1) 
      { 


       $this->session->set_userdata('mem_id', $user->id); 

       $this->session->set_userdata('mem_last_login_date', $user->last_login_date); 

       $this->session->set_userdata('mem_created_on', $user->created_on); 
       //-- Update last login of successfull Login 
       $sql = "update table set last_login_date = NOW() where id=$user->id"; 
       $query = $this->db->query($sql); 
       return TRUE; 
      } 

         } 

      else { 
       return FALSE; 
      } 

     } 
    } 

如果我将停止存储值到会话的用户数据比它工作正常但与会话的CloudFlare给我的502错误页面。

请告知 在此先感谢您的时间和支持。

+0

这是否帮助http://eric.tendian.io/cloudflare-php-sessions – RiggsFolly

回答

0

520错误通常表示存在大量的Cookie或者返回的头部,这些头部在我们的末端碰到代理缓冲区限制。发送给我们的支持团队的HAR file将帮助我们找出问题所在。

+0

谢谢,它解决了现在我做了会话中的一些变化。 – RAk

+0

感谢您的更新:) – damoncloudflare

+1

@RAK你能提供一些你改变的信息来解决这个问题吗? – mcryan

1

如果别人运行到这个问题,我想出了涉及扩展核心Session库,最终降低了呼叫sess_write()并通过扩展,_set_cookie()数量的解决方案。

MY_Session.php:

class MY_Session extends CI_Session { 

    function set_userdata($newdata = array(), $newval = '', $write_session = true) 
    { 
     if (is_string($newdata)) 
     { 
      $newdata = array($newdata => $newval); 
     } 

     if (count($newdata) > 0) 
     { 
      foreach ($newdata as $key => $val) 
      { 
       $this->userdata[$key] = $val; 
      } 
     } 

     // Do not write the session (set the cookies) unless explicitly specified 
     if ($write_session) { 
      $this->sess_write(); 
     } 
    } 

    function set_flashdata($newdata = array(), $newval = '') 
    { 
     if (is_string($newdata)) 
     { 
      $newdata = array($newdata => $newval); 
     } 

     if (count($newdata) > 0) 
     { 
      foreach ($newdata as $key => $val) 
      { 
       $flashdata_key = $this->flashdata_key.':new:'.$key; 
       $this->set_userdata($flashdata_key, $val, false); // Do not update the cookie in the foreach 
      } 
     } 

     // Save the cookie now that all userdata has been set 
     $this->sess_write(); 
    } 

    function _flashdata_mark() 
    { 
     $userdata = $this->all_userdata(); 
     $newUserData = array(); 
     $userDataToUnset = array(); 
     foreach ($userdata as $name => $value) 
     { 
      $parts = explode(':new:', $name); 
      if (is_array($parts) && count($parts) === 2) 
      { 
       $new_name = $this->flashdata_key.':old:'.$parts[1]; 
       $newUserData[$new_name] = $value; 
       $userDataToUnset[$name] = ''; 
       // Cookies were originally set in this loop. Moved to the end of the function 
      } 
     } 

     // Save all changes outside of the loop 
     if (count($newUserData) > 0) { 
      $this->set_userdata($newUserData); 
      $this->unset_userdata($userDataToUnset); 
     } 
    } 
}