0

In my project I integrated magento 2 and codeigniter. After Login from Magento I can access codeigniter also. I saved the session into a file.

when I logout from codeigniter I will re-write the session file to get magento logout.

Everything is working perfectly except after logout from codeigniter the session file still shows in header?.

How can i solve this issue?. thanks in advance for your valuable suggestion.

funciton logout

function logout() {
     //unset session
     foreach ($this->session->userdata as $key => $value) {
        if (strpos($key, 'inf_') === 0) {
            $this->session->unset_userdata($key);
         }
     }

     //clear magento session file
     if (isset($magento_status)) {
         $this->unset_store_session_data();
     }
     $magento_url = STORE_URL;

     //header("location:$magento_url");
     echo '<script>window.location="'.$magento_url .'";</script>';}

clear session file

function unset_store_session_data() {
    $oc_sess_data = $this->get_store_session_data();

    if(isset($_COOKIE['PHPSESSID']) && isset($oc_sess_data['customer_base']['inf_logged_in'])) {

        //unset($oc_sess_data);
        unset($oc_sess_data['customer_base']);
        unset($oc_sess_data['default']);
        //$oc_sess_file = dirname(dirname(dirname(__DIR__))) . '/store/system/storage/session/sess_' . $_COOKIE['PHPSESSID'];
        $oc_sess_file = dirname(dirname(dirname(dirname(__DIR__)))) . '/var/www/session/sess_' . $_COOKIE['PHPSESSID'];
        if (is_file($oc_sess_file)) {
            $handle = fopen($oc_sess_file, 'w');
            flock($handle, LOCK_EX);
            $oc_sess_data = $this->encode_session_data($oc_sess_data);
            fwrite($handle, $oc_sess_data);
            fflush($handle);
            flock($handle, LOCK_UN);
            fclose($handle);
        } 
    }

    //$oc_sess_data1 = $this->get_store_session_data();
    //print_r($oc_sess_data1);die();
}

using this function i cleared the session file and it will redirect to magento store side. session successfully cleared. but customer name still shows in header.

  • Please share your code which you have using for logout – Amit Bera Feb 23 '18 at 7:44
  • I added the code please check it. – Midlaj Feb 23 '18 at 8:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.