From c20dfafef1a6b4888113a1ca7c8bee85bbfd78e7 Mon Sep 17 00:00:00 2001 From: Andy Smith Date: Wed, 18 Mar 2015 08:12:12 +0000 Subject: [PATCH] Consolidated session->set_userdata calls to fix 502 errors when behind an Nginx proxy --- application/controllers/qso.php | 36 ++++++++++++++++++++++----------- 1 file changed, 24 insertions(+), 12 deletions(-) diff --git a/application/controllers/qso.php b/application/controllers/qso.php index 8f944648..a0c8ab25 100644 --- a/application/controllers/qso.php +++ b/application/controllers/qso.php @@ -43,12 +43,20 @@ class QSO extends CI_Controller { $this->logbook_model->add(); // Store Basic QSO Info for reuse - $this->session->set_userdata('band', $this->input->post('band')); - $this->session->set_userdata('freq', $this->input->post('freq')); - $this->session->set_userdata('mode', $this->input->post('mode')); - $this->session->set_userdata('sat_name', $this->input->post('sat_name')); - $this->session->set_userdata('sat_mode', $this->input->post('sat_mode')); - $this->session->set_userdata('radio', $this->input->post('radio')); + // Put data in an array first, then call set_userdata once. + // This solves the problem of CI dumping out the session + // cookie each time set_userdata is called. + // For more info, see http://bizhole.com/codeigniter-nginx-error-502-bad-gateway/ + $qso_data = [ + 'band' => $this->input->post('band'), + 'freq' => $this->input->post('freq'), + 'mode' => $this->input->post('mode'), + 'sat_name' => $this->input->post('sat_name'), + 'sat_mode' => $this->input->post('sat_mode'), + 'radio' => $this->input->post('radio') + ]; + + $this->session->set_userdata($qso_data); // Get last Ten QSOs $data['query'] = $this->logbook_model->last_ten(); @@ -103,12 +111,16 @@ class QSO extends CI_Controller { $this->logbook_model->create_qso(); // Store Basic QSO Info for reuse - $this->session->set_userdata('band', $this->input->post('band')); - $this->session->set_userdata('freq', $this->input->post('freq')); - $this->session->set_userdata('mode', $this->input->post('mode')); - $this->session->set_userdata('sat_name', $this->input->post('sat_name')); - $this->session->set_userdata('sat_mode', $this->input->post('sat_mode')); - $this->session->set_userdata('radio', $this->input->post('radio')); + $qso_data = [ + 'band' => $this->input->post('band'), + 'freq' => $this->input->post('freq'), + 'mode' => $this->input->post('mode'), + 'sat_name' => $this->input->post('sat_name'), + 'sat_mode' => $this->input->post('sat_mode'), + 'radio' => $this->input->post('radio') + ]; + + $this->session->set_userdata($qso_data); // Get last Ten QSOs $data['query'] = $this->logbook_model->last_ten();