Welcome Guest, Not a member yet? Register   Sign In
Setting sessions with an Ionic Framework App
#1

Hi,

    I have a website using CodeIgniter as a server-side framework mainly for managing user sessions.

    In the website, when logging in a user, session is stored and there is no problem.

    Now I'm developing a Ionic app using the same API than the website use.

    The problem is that the session is not stablished. I'm trying to figure out why but do not find anything.

    My set session function is:

Code:
private function setSession($id, $email) {
          $this->load->library('session');
          $this->session->sess_expiration         = 0;
          $this->session->sess_cookie_name        = 'ci_sessions';
          $this->session->sess_expire_on_close    = FALSE;
          $this->session->sess_encrypt_cookie     = FALSE;
          $this->session->sess_use_database       = TRUE;
          $this->session->sess_table_name         = 'ci_sessions';
          $this->session->sess_match_ip           = FALSE;
          $this->session->sess_match_useragent    = TRUE;
          $this->session->sess_time_to_update     = 86400;
          $this->session->set_userdata( array('user' => $id, 'hasSession' => true, 'id' => $id, 'email' => $email) );
      }
Each time I navigate in the website, I check user session invoking the following function:
Code:
public function isSessionActive() {
         $this->load->library('session');
         if ( $this->session->userdata('user') ) {
             return true;
         } else return false;
     }

In case the session variable 'user' exists, it indicates that there is a session active for the user. As I mentioned above, using this code, in the website it works fine, but when using it in an Ionic App, the function isSessionActive() always returns false.
What's happening? Any help?
Reply
#2

Hello!

When using Cordova (which is what ionic is build on), sessions do not always persist. For you to maintain a session, I'd recommend looking into using the app localstorage feature to maintain a session state. I've seen several different implementations but I recommend having an access token that you can reset/update that is sent securely via the header.
Codeigniter is simply one of the tools you need to learn to be a successful developer. Always add more tools to your coding arsenal!
Reply
#3

(05-17-2016, 07:41 PM)albertleao Wrote: Hello!

When using Cordova (which is what ionic is build on), sessions do not always persist. For you to maintain a session, I'd recommend looking into using the app localstorage feature to maintain a session state. I've seen several different implementations but I recommend having an access token that you can reset/update that is sent securely via the header.

Hi,

    Is there any example I could use for sending tokens in header?

Thanks.
Reply
#4

If you use jQuery you can set your headers in the $.ajax method.

The documentation is here: http://api.jquery.com/jquery.ajax/
Codeigniter is simply one of the tools you need to learn to be a successful developer. Always add more tools to your coding arsenal!
Reply




Theme © iAndrew 2016 - Forum software by © MyBB