mokko211
mokko211

Reputation: 607

How to use session to work between php webservices and android

I have an android application which uses php webservices. I have created the login.php which will validates the username, password sent from the android application. Once validated, a session is created such as follows:

session_start();
$_SESSION['userId'] = $id;
$_SESSION['username'] = $username;

On the client-side I have this:

HttpContext httpContext = new BasicHttpContext();
HttpResponse httpResponse = httpClient.execute(httpPost, httpContext);
HttpEntity entity = httpResponse.getEntity();

When I debug, I see that the httpReponse contains a PHPSESSID. I do know that I will need this information for comparison between the session_id on the server-side before executing any queries.

However, I do not know how to retrieve this "Set-Cookie" and send it to the server-side for comparison? A piece of code or tutorial will be extremely helpful.

Thank you

Upvotes: 3

Views: 12148

Answers (1)

tix3
tix3

Reputation: 1152

You can see this answer for a solution. HttpClient supports cookies by default and you will have to enable them so that php sessions work.

Upvotes: 1

Related Questions