3

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

1
  • Would you mind posting the response that that is returned? My best guess is that is just a JSON object. Commented Feb 24, 2013 at 23:14

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

3 Comments

Thanks for the example.I managed to retrieve the String value of the PHPSESSID. Now, how do I do to compare this value to the opened session on the server? Is there some php code that I need to write?
You can see a basic example of sessions in php manual php.net/manual/en/session.examples.basic.php. What are you trying to do exactly ? Can you share some of your code ?
I want to make sure if the open session_id on the server_side is the same as the client_side. So, for example - I have this "d9fq1lrd8t0bn9fkfmgdc1oj36" retrieved as a cookie from a HTTPResponse. Now, I will use this string and compare it with the session_id on the server to verify if the user is logged in. But I cannot seem to figure out how to do it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.