Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to manage session tokens among various client apps (android/iphone) from server side php and mysql?

I have a rest API developed using php and mysql.

I need manage different client apps including Android and iPhone. I just want to allow only one user from one type of device.

For instance: if a user is using the app on Android and iPhone at the same time, this can be allowed. However, if a user tries to use the app more than one time on the same device, either Android or iPhone, it would not be allowed.

How I can achieve this? I am issuing 3 types of tokens at a time, such as token_iphone, token_android, etc. Currently my problem is, if any user logged in from the same type of device, the first instance the user started get its token expired or replaced with the new one.

Any help would be highly appreciated.

like image 295
Sibi T Mathew Avatar asked Nov 11 '22 18:11

Sibi T Mathew


1 Answers

If i were you I'd manage this with memcached, you create an array identified by the username key and for each token you add to this array a couple device => token, when you have a conflict you either pull the correct token from the array or block the new device. if you have several servers you could also mange php sessions via memcached

User_a {
    iphone: 12345,
    android:67890,
    pc: abcdef
}
like image 156
sathia Avatar answered Nov 15 '22 05:11

sathia