在登录Android应用程序后,我怎么在PHP API创建令牌会议?
这样的:
我想确保当用户登录它会留在会议上无论发生什么事(应声,关机/关机/重启,使应用程序)的同时,用户的信息数据将全部被发送该活动的应用程序到Web服务器。
我简单地使用:
在session_start();
$ _SESSION [用户名] = $用户;
$ _SESSION ['权威性'] =真;
如果让我怎么通过这个会议到Android应用程序?
![QQ手机令牌 for Android 1.5 河源下载站](https://p.xsw88.cn/allimgs/daicuo/20230906/387.png)
在Android应用程序登录身份认证:
HttpClient的客户端=新DefaultHttpClient();
字符串URL =http://www.somewebsite.com/login.php?username="+username+"&password="+password;
HTTPGET请求=新HTTPGET(URL);
//得到响应
ResponseHandler的<字符串> ResponseHandler的=新BasicResponseHandler();
response_str = client.execute(请求,ResponseHandler所);
PHP的Android验证的登录会话的Cookie
解决方案 当你的Android应用程序首先调用您的登录API,检索经过验证的响应代码字段 在本地存储这些令牌领域,在应用程序,使用共享preferences
的http://developer.android.com/reference/android/content/Shared$p$pferences.html
(此存储仍然存在应用程序/操作系统的生命周期之外,它还将应用程序或设备重启的重新开张后,在那里) 当你打电话给你的Web服务(PHP),追加令牌参数这看起来像一些相关的信息在这里:
的http://www.androidhive.info/2012/08/android-session-management-using-shared-$p$pferences/
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
解决方案
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 parametersThis looks like some relevant information here:
http://www.androidhive.info/2012/08/android-session-management-using-shared-preferences/
相关推荐
最新文章