Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.2k views
in Technique[技术] by (71.8m points)

php - Application with session management in the server side

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...