应用程序与服务器端的会话管理 [英] Application with session management in the server side

查看:94
本文介绍了应用程序与服务器端的会话管理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要使用带有authinticationloginmechanisim的iOS客户端创建一个基于服务器的(php)应用程序,但我不知道iOS中的会话。我的应用程序需要登录我的网站(基于PHP的网站)来获取数据。我不知道一个是iPhone客户端的会话是否在服务器中?



详细信息:



之后将登录请求从iPhone客户端发送到我的Web应用程序,我想这里会话是在我的webapp中创建的(对吗?),我的下一个请求呢?我可以访问为第一个请求创建的相同会话。换句话说:我可以在网络会话中(在服务器中)共享数据,以便在登录后由iOS客户端发送的每个请求中可访问吗?

解决方案

会话是服务器端的概念 - 客户端没有会话。



通常发生的是服务器在您登录后在响应头中设置cookie,并且该cookie包含会话ID,以便在后续请求中,服务器知道客户端正在使用该会话,因为它匹配cookie。 / p>

Cookie会自动在iOS上运行,因此您根本不需要做任何事情。 NSURLRequests有一个属性HTTPShouldHandleCookies,默认为YES,所以一切都应该默认工作。



如果它不起作用(或者如果你只是想看看发生了什么),您可以使用NSHTTPCookieStorage API访问iOS中的cookie。看一下[NSHTTPCookieStorage sharedHTTPCookieStorage],它的工作方式有点像NSDictionary。这是您登录后应设置会话cookie的地方。


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?

解决方案

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.

这篇关于应用程序与服务器端的会话管理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆