Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Application with session management in the server side

Tags:

php

ios

session

I need to create a server based (php) application with iOS client with authintication "login" mechanisim but i dont known about session in iOS. My application needs login to my website (PHP based website) to get data. I dont known a is the session for the iPhone client is keept in the server?

Details:

After sending the login request from iPhone client to my web application, I think here a session is created in my webapp (right?), what about my next request? can I access the same session created for the first request.. In another word : can I share data in the web session (in the server) to be accessible in each request sent by iOS client after login?

like image 342
Saeed Avatar asked Feb 05 '12 10:02

Saeed


1 Answers

Sessions are a server-side concept - there is no session on the client side.

What normally happens is that the server sets a cookie in the response headers after you log in, and that cookie contains the session ID so that on subsequent requests, the server knows that the client is using that session because it matches up the cookie.

Cookies work automatically on iOS, so you shouldn't have to do anything at all. NSURLRequests have a property HTTPShouldHandleCookies that defaults to YES, so everything should just work by default.

If it's not working (or if you just want to see what's going on), you can gain access to the cookies in iOS using the NSHTTPCookieStorage APIs. Take a look inside the [NSHTTPCookieStorage sharedHTTPCookieStorage], which works a bit like an NSDictionary. That's where the session cookie should be set after you log in.

like image 64
Nick Lockwood Avatar answered Sep 29 '22 11:09

Nick Lockwood