skip to Main Content

codeigniter session destroy on redirect from graph APi facebook some time its work and some time it destroy session and take a user to login page

Here is Config.php Session code

$config['see_driver'] = 'database';
$config['see_cookie_name'] = 'ci_session';
$config['see_expiration'] = 0;
$config['see_save_path'] = 'ci_sessions';
$config['see_match_ip'] = FALSE;
$config['see_time_to_update'] = 10000;
$config['see_regenerate_destroy'] = FALSE;

and this is how i am setting user session after login and authenticate from database in User_controller.php

private function __set_user_session($user)
    {
        if(isset($user))
        {
            $data = [
                'user_id' => $user['id'],
                'ilocal_user_id' => $user['ilocal_user_id'],
                'package_id' => $user['package_id'],
                'no_available_business' => $user['no_available_business'],
                'name' => $user['name']
             ];

            $this->session->set_userdata($data);
        }
    }

After face book connect and on redirect this method is called and its automatically redirect to user on login page i dont know why he is destroying a session

public function connect_facebook_account($business_id)
    {
        $this->__load_business($business_id);
        try
        {
            if(isset($this->data['business'] ))
            {
                $this->fb = new Facebook();
                $this->data['facebook_url'] =  $this->fb->get_login_url($business_id);
                if(isset($_GET['code']))
                {
                    $social_acccount_info = $this->fb->fetch_access_token();
                    if($social_acccount_info['status'] === TRUE)
                    {
                        $social_acccount_info['business_id'] = $business_id;
                        // save data of connected account
                        $this->__create_social_account($social_acccount_info);

                        redirect($this->session->social_page_redirect);
                    }
                }

                if (is_page_connected($business_id) === NULL)
                {
                    $this->data['pages'] = $this->fb->fetch_facebook_pages($business_id);
                }


            }

        }
        catch(Exception $e)
        {
            $this->session->set_userdata('message', $e->getMessage() );
        }

    }

this code is working on fine on localhost and sometime also works on production server but most of the time it destroy session on production but working on local machine ?

any solution ?

4

Answers


  1. This is a frequent problem that I spent quite a bit of time tracking a few months ago. This article includes a good workaround though not a full resolution… works like a charm, generally.

    http://blog.thecodingbox.me/codeigniter-frequent-session-expiration-fix/

    Login or Signup to reply.
  2. Make sure that in your config.php file, the correct array key is used; change:

    $config['see_driver'] 
    

    to

    $config['sess_driver']
    

    ..and so on

    Also make sure the session cookie name is not the same for all your environments, this could cause a session to be lost when developing locally and also checking the production/dev site.

    Login or Signup to reply.
  3. Try the below code in config.php

    $config['sess_driver'] = 'files';
    $config['sess_cookie_name'] = 'ci_session';
    $config['sess_expiration'] = 7200;
    $config['sess_save_path'] = NULL;
    $config['sess_match_ip'] = FALSE;
    $config['sess_time_to_update'] = 300;
    $config['sess_regenerate_destroy'] = FALSE;
    
    Login or Signup to reply.
  4. $config['sess_driver'] = 'files';    
    $config['sess_cookie_name'] = 'ci_session';    
    $config['sess_expiration'] = 7200;    
    $config['sess_save_path'] = NULL;     
    $config['sess_match_ip'] = FALSE;     
    $config['sess_time_to_update'] = 600;    
    $config['sess_regenerate_destroy'] = FALSE;    
    

    Try this code in config.php
    if $config[‘sess_expiration’] =0 it will redirect to your route which ever you mentioned. Set session time according to your convenient time in seconds and update in $config[‘sess_expiration’enter code here] = 3600 for 1 hour. if you want to update session time automatically then $config[‘sess_time_to_update’] = 600; should be in seconds.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search