Accessing $_SESSION from android

Go To


I built a website with PHP, and now and am working on an application to go with it, (however I am not new to php nor Android, just to them together) and I am able to login, and get Status Code: 200 response (successful login), however in the headers list when I print out

Header[] heads = response.getAllHeaders();

Does not show the fact that (in php) I called

header("Location: success.php") or "Location: failure.php" for failure, so I'm not sure why it is returning the 200 at all, it just is.

but what I really need to know how to access my $_SESSION variables I set in the php code so I can go about my navigation signed in just like I would on my website. If you need more information, just ask.

2012-04-04 04:38
by Samuel
One question per question - Ignacio Vazquez-Abrams 2012-04-04 04:42
sorry, I have seen countless two-part questions, I dont see why this is any different; I updated the question none the less - Samuel 2012-04-04 04:47
@Samuel if u more descriptive about php variable , i can solve your proble - Rizvan 2012-04-04 04:51


Session variables are set on the server, and can't be accessed from the client. If you're seeing a 200 then you've already missed the 3XX response with the Location header.

2012-04-04 04:53
by Ignacio Vazquez-Abrams


You should have the following code to retrieve all the values stored in the session

 Print_r ($_SESSION);

If you want to retrieve only a particular variable value, then pass it as follows

 // this starts the session 
 echo $ses;

"XXX" is the session variable name

2012-04-04 05:52
by skkishor


The default behavior of an website that should work with an app is that it provides an API that will be used for communication.

That means that your server has some url you call while sending some data (via json for example). The server process it and sends back some feedback.

In your case you should just send the login data (use SSL!) and the server shouldn't redirect but send you data back where to go from there so that your app knows if everything is right or not.

To you PHP question: Without your php sending the $_SESSION data to your android app, there is no way for android to get the information. Everything else would be a vulnerability on each server running PHP.

2012-04-04 08:30
by WarrenFaith