多个 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屋!