问题
After login in android app, how do I create a token session in the php api?
Like this:
I would like to make sure that when user log in it will stay in session no matter what happens (crashed, shut down/power down/reboot, leaving the app) at same time the user info data will be sending with all the activities in the app to the webserver.
Do I simply use:
session_start();
$_SESSION['username'] = $user;
$_SESSION['auth'] = "true";
If so how do I pass this session into the android application?
Login Authentification in Android App:
HttpClient client = new DefaultHttpClient();
String url = "http://www.somewebsite.com/login.php?username="+username+"&password="+password;
HttpGet request = new HttpGet(url);
// Get the response
ResponseHandler<String> responseHandler = new BasicResponseHandler();
response_str = client.execute(request, responseHandler);
php android authentication login session-cookies
回答1:
- When your Android application first calls your Login API, retrieve the token fields from the validated response
- Store these token fields locally, in the app, using SharedPreferences
http://developer.android.com/reference/android/content/SharedPreferences.html
- (this storage persists outside of the app/os lifecycle, it will still be there after a relaunch of the app or device reboot)
- Whenever you call your web service (php), append the token parameters
This looks like some relevant information here:
http://www.androidhive.info/2012/08/android-session-management-using-shared-preferences/
来源:https://stackoverflow.com/questions/14005460/android-login-with-token-session-like-user-logins-and-stays-in-session-until-lo