Could we use session to create a global variable for all client?

耗尽温柔 提交于 2019-12-24 09:39:49

问题


I saw this example in php manual page http://www.php.net/manual/en/session.examples.php The example will create a global session for all client. Can I use this example to create some global application for all client, instead of save it to DB or local file. What're the pros and cons of this method? Thanks for any help.


回答1:


It might work, but I wouldn't recommend it... to much scope for potential confusion by othe rdevelopers working with the code, potential issues if you update session variables within the wrong scope, and the use of the term "session" for something that is not session-related can lead to a whole world of confusion




回答2:


Yes it is possible by sharing the session id between two clients but sessions are only used to store temporary data of a user. So once a session is destroyed there is no way to retrieve that data.




回答3:


No, this is not possible, or advised. A session is bound to one client, and clients do not share a session.



来源:https://stackoverflow.com/questions/3760270/could-we-use-session-to-create-a-global-variable-for-all-client

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!