How to create session variables after Login and destroy it as well after Logout?

Good Day!
Currently I have my application connected to a PHP server using MySQL as my backend service.

I wonder If someone knows on how could I have my session inside my application.
What i want to achieve is/are:

  • Have my LOG-IN Session Variables (Username or/and Password).
  • Use my Session Variables to display a certain user’s Profile details.

Please help me out. I want to start a session at every page whenever I logged in and destroy it as well after i logged out of my application.

Hi there :smile:

I would recommend looking into HTML5 local storage:

You can create a local storage object like so:

$window.localStorage['myStorageObject'] = JSON.stringify(myArray);

And retrieve it like so:

return JSON.parse($window.localStorage['myStorageObject'] || '[]'); 

You could create an object with your required properties on login and save the object in local storage. From there when you logout you can just destroy the local storage object.

I would recommend creating a factory with all your local storage operations and dependency injecting it into which ever controllers would require it.

Hope this help you :smile:

I use this for my project to save local data

I have used ionic’s factory to store the session variable. Got some idea from the link. Thanks!

Got some idea from that. But I have solved my problem using Angular’'s factory service. Thanks a lot!

sir can i ask you did you solve your problem? because i also want to have a login session and destroy it when i logout thank for your response :smiley:


iam waiting too @Pajimola :smiley:

Hi guys!
You might consider using Secure Storage to keep track of your login information, here are two links that I hope will help you.

thx, but i realy apriciate if you have some example code, i feel more confident learn with actual code…

i already solve my problem…