多个PHP会话 [英] Multiple PHP Sessions
问题描述
我要为一个网站构建一个PHP应用程序,该网站已经在同一域/服务器上运行了另一个PHP应用程序. 我的应用程序当然将使用会话,并且我不希望我的会话干扰现有的应用程序. 例如,如果我想使用$ _SESSION ['username'],也许另一个应用程序也使用$ _SESSION ['username'],这可能是一个问题. 我并不是在寻找额外的安全层,我相信与之共享主机的应用程序.我只想避免错误.
I am to build a PHP application for a website that already has another PHP application running on the same domain/server. My app will of course be using sessions, and I don't want my sessions to interfere with the existing app. For example if I want to use $_SESSION['username'], maybe the other app also uses $_SESSION['username'], which could be a problem. I'm not looking for an extra layer of security, I trust the application I'm sharing the host with. I just want to avoid bugs.
一种方法是执行类似$ _SESSION ['MY_APP_NAME'] ['username']的操作,但我想知道是否有更简单的方法.
One way would be to do something like $_SESSION['MY_APP_NAME']['username'], but I want to know if there is an easier way.
我在PHP文档中看到一个名为"session_module_name"的函数.这个名字听起来不错,但是文档并没有真正解释它的用途.
I see on the PHP documentation that there is a function called 'session_module_name'. The name sounds good, but the docs don't really explain what it is for.
有什么建议吗?
推荐答案
有一种更简单的方法: session_name .
There is an easier way: session_name.
在调用session_start();
之前,请先调用 session_name("something");
(在此将任何内容更改为所需的内容)被称为).
Prior to calling session_start();
call session_name("something");
(where you change something to whatever you want it to be called).
这篇关于多个PHP会话的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!