Android PHP SESSION ID

My app is working great on the iphone and OSX simulator. It successfully connects, logs in, and retrieves db data back from my php server.

However, the same code on Android has a serious issue. It appears the server is assigning a SESSION ID to all connections and remembering the IP/Session of the caller for iphone/OSX, but it is NOT remembering the session created from my Android phone.

Essentially, the login call (name, password) works properly on Android… But the next call (to get the USER ID needed for subsequent calls, which is done through network.request) is not recognized as from the same session by the server, and the USER ID requested comes back as null (Android only - works fine on iOS and OSX).

I checked my relatively new phones browser settings, and cookies are enabled in the default browser. There doesn’t appear to be any other settings on the device to affect cookies/sessions.

OK, so I messed around with the request headers and body a little, but haven’t had much luck…

Has anyone else solved this issue? Is there a way to see/access the headers returned by the server for network.request calls? (maybe I can pass the cookie info around manually?) [import]uid: 79933 topic_id: 25630 reply_id: 325630[/import]

On Android, cookies are stored in memory and not to file by default. That would explain why your session is being forgotten. It’s definitely possible for us to override this behavior on our end… and it’s definitely worth doing to match iOS’ default behavior. Nice catch.

So, when is the session “forgotten”?
After closing the web popup?
When leaving and returning to your app? [import]uid: 32256 topic_id: 25630 reply_id: 103586[/import]

Hi - thanks for the quick reply Joshua!

The session (on Android only) looks like it is forgotten after each and every call the app makes to the server (for network.request)… It’s never remembered on the android it seems.

My app is a corona client talking directly through network.request to a remote php server… (not using a webpopup for a UI, but corona tableviews, etc)

So the first call is to login the user as such (pass in name & pw):
print(" Login Account: " … loginURL )
network.request( loginURL, “GET”, loginListener )

The very next call is to get the userID from the server:
print(" get user id URL: " … infoURL )
network.request( infoURL, “GET”, updateUserInfoListener )

Which works/server gets the right ID (finds the users session internally) for the app running on both iOS devices and on the OSX simulator.

For android, however, the server returns null for the user id – not recognizing the session. Any ideas? [import]uid: 79933 topic_id: 25630 reply_id: 103594[/import]

Hmmm… I had no idea Mac and iOS automatically handled cookies for network.request(). On Android and Windows, we would have to handle cookies ourselves by reading a server’s response header for a “set-cookie” field, store it, and then add the cooking to the next request if it is heading to the same URL. Bottom line, we would have to do all of the grunt work ourselves.

I’ll write up a feature request for this.

In the meantime, the only possible work-around that I can think of is to switch to web popups which do have cookie support. [import]uid: 32256 topic_id: 25630 reply_id: 103609[/import]

OK, thanks - it sounds like you understand what’s going on exactly!

I’ll investigate routing everything through a web-popup for now…

Just to make sure: There’s no way for the app to access the network.request header that is returned by the server (in the apps response listener)? If I could read the headers coming back, I might be able to create a good header to pass back on the next network.request call I make… (add the vars in myself before passing back to the server)

Also, the other big thing my app could use is android maps… No word on any impending big map update news, is there?

Thanks for all your help Joshua! [import]uid: 79933 topic_id: 25630 reply_id: 103613[/import]

Providing response headers to the Lua listener is on our to-do list as well. In fact, that is a higher priority feature for us to implement. A lot of Corona developers have requested header support, so we understand the importance of this. No ETA yet, but I’ll push to have this done by the next Corona SDK release.

Regarding maps, we did promise to do this for the next Corona SDK release… but right, we keep pushing it off due to other higher priority tasks that keep getting in the way. What makes integrating maps extra difficult is that Google’s version of the maps library is not supported on Kindle Fire and Nook. We would have to use a 3rd party maps library, such as Microsoft’s Bing Maps library. That’s what the real-estate app Zillow uses. Problem being that integrating both libraries would be twice the work for us and plus we’re not sure how the rest of the Corona community would feel about it. Nothing on Android is ever easy.

That said, you can display maps via a web popup on Android. Please see sample app “Hardware\GPS” that is included with the Corona SDK for an example. The web popup solution will work on all platforms, provided that you have an Internet connection of course. [import]uid: 32256 topic_id: 25630 reply_id: 103620[/import]

Great! Thanks for the info and tips Joshua! Went through a lot of things, and all in the same day. You even got time to go grab a well deserved cold beverage of your choice before 5! [import]uid: 79933 topic_id: 25630 reply_id: 103621[/import]

Glad I could help!
And how did you know I had a cold frothy beverage last Friday?!
(Looks around for hidden cameras.) :stuck_out_tongue: [import]uid: 32256 topic_id: 25630 reply_id: 104053[/import]

I’ve been having a similar problem. I’ve written a asynchronous game server in Rails which uses permanent cookies to maintain a session once the player logs in. Everything works fine in the simulator and on the iPhone, but when I try to run my game on my Android tablet, the authentication fails on the server. I can log in and create the session but subsequent network calls don’t seem to have the session cookie attached and so the server rejects them. I have a simple sample that demonstrates this problem if you need it. [import]uid: 145841 topic_id: 25630 reply_id: 104260[/import]

@Joshua

Regarding the maps, I don’t think it’s a problem not to have the mapping functions for the Nook or the Kindle Fire, they are not formats that you are not really going to use mapping functions on.

Google Maps integration would probably be the best solution all in all as then it is in line with the iOS version, having different maps on the same app on different devices is probably not wanted.

Does that make sense?

We are currently developing an App that works great on iOS with the mapping functions and we need them really badly on the Android, I have implemented the Google maps in a web view on the Android version but I can’t get the interaction that I can with the iOS version. [import]uid: 8697 topic_id: 25630 reply_id: 104296[/import]

We still plan on implementing Google maps on Android for the upcoming release. So no worries there. We’re just not sure if we “need” to implement a 3rd party solution such as Bing Maps as well because we know Kindle Fire and Nook are very popular devices. It’s good to hear that you’ll be satisfied with only Google’s version of maps at the moment. What’s nice about that solution is that we do not have to “bloat” the APK with a map library since it is included on devices support it.

That said, we’ll still write the code to support multiple map solutions like we did for in-app purchases on Android. We at least need a new Lua API to determine if Maps is supported on the device.

Thanks for your feedback. [import]uid: 32256 topic_id: 25630 reply_id: 104477[/import]

Thanks Joshua :slight_smile:

When is the next release likely with Google maps implemented for Android? Approximate is good enough.

Thanks [import]uid: 8697 topic_id: 25630 reply_id: 104478[/import]

I can’t commit to an exact date yet… but it’s got to happen in the next 2 months. We’ve committed to this feature back in December (see the below blog post) so we must good on our commitment.
http://blog.anscamobile.com/2011/12/state-of-the-corona-address/

Our top priority at the moment is to fix all of the rendering and masking issues that have come up since build 759… which mainly affected low-end Android devices. Any new features don’t mean a damn until all of the rendering issues have been fixed. I hope you agree. [import]uid: 32256 topic_id: 25630 reply_id: 104486[/import]

I have also run into this issue. We are using native.showWebPopup and still experiencing this issue on Android. [import]uid: 140942 topic_id: 25630 reply_id: 104510[/import]

Kirei,

Android Web Popups will remember their cookies up until you close them because their cookies are stored in memory instead of to file. It’s a different issue compared to the original thread post where network.request() on Android (or Windows) does not store cookies at all. [import]uid: 32256 topic_id: 25630 reply_id: 104513[/import]

Joshua — This news, < 2 months for Android maps, is great, and the implementation you mentioned is just fine too! (So feel free to ignore the rest!)

With releasing an Android mapView being top priority, there might be a few quick things (wouldn’t want you to delay android maps though…) you could do to really increase the integration/usability of maps… I’ve got a couple “wishes”, maybe one is easy?

  • Receive an event when the mapView is touched/tapped, etc. Even if I can’t get hit detection on the pins inside the mapView, being able to tell the map was touched could be helpful – For example, I could fix the mapView/not allow user scrolling, but then when it’s touched, process the input myself and move/update the mapView programmatically (would solve problems like below).

  • Access the mapViews variables/settings. Being able to access the mapViews current settings, such as center-point location, or current map boundary coordinates could be helpful. In the current implementation, if the user scrolls the map, the app cannot tell where they are currently looking at (app can’t access any current mapView settings).

Again, Android mapView ASAP is tops on the list for your existing developer base, as I’m sure you noticed. Any free/“gimme” (very quick/easy) features would also be greatly appreciated. [import]uid: 79933 topic_id: 25630 reply_id: 104539[/import]

mpappas,

We’ll keep your map feature requests in mind when we implement it on Android. If providing access to map settings prove simple/easy enough for us to implement, then we may just sneak those changes in. The center on location option sounds like it would be a good thing to have. [import]uid: 32256 topic_id: 25630 reply_id: 104766[/import]

Is something being done about this?

I can not build an app to android until cookie information is being saved. I’ve tested on several androids and they are giving the same behavior.

iOS has no issue. [import]uid: 30130 topic_id: 25630 reply_id: 139368[/import]

cowbear,

We now have MapView support on Android. So, you don’t have to implement your own via a WebView. Please see sample app “Interface/MapView” that is included with the Corona SDK for an example on how to use map views on Android. [import]uid: 32256 topic_id: 25630 reply_id: 139373[/import]

Oh sorry, I wasn’t being specific.

Cookie data is not being saved on android as stated by the topic creator. Every time I send a network.request API call on android to my web-server, the PHP Session ID is not being saved by the device and seems to forget it, leaving users unable to sign into their accoumt, and leaving me unable to build my app for android users.

I don’t have this issue on any iOS device, but I have tried on several android devices giving the same issue. [import]uid: 30130 topic_id: 25630 reply_id: 139484[/import]