Php (Spotify)如何停止跨浏览器会话共享?

Php (Spotify)如何停止跨浏览器会话共享?,php,session,cross-browser,spotify,fat-free-framework,Php,Session,Cross Browser,Spotify,Fat Free Framework,我正在使用SpotifyAPI,出于某种原因,他们的会话类块将自己的数据存储在$\u会话中。作为解决方法,我编写了一个类“SystemHelper”: 名称空间应用程序 class SystemHelper { /** * if session_id is empty string, then session_id has not been initialized * then set session_id named 'se

我正在使用SpotifyAPI,出于某种原因,他们的会话类块将自己的数据存储在$\u会话中。作为解决方法,我编写了一个类“SystemHelper”:

名称空间应用程序

    class SystemHelper
    {

        /**
         * if session_id is empty string, then session_id has not been initialized
         * then set session_id named 'session1'
         * start session needs 2 parameters, name and value
         * always close session after writing
         *
         * @param   string  $name   any given name
         * @param   [type]  $value  any given value
         *
         */
        public static function customSessionStore($name, $value)
        {
    
            if (session_id() == '') {
                session_id('session1');
            }
            session_start();
            $_SESSION[$name] = $value;
            session_write_close();
        }
现在可以在$\u会话中存储数据,但问题是,只要我使用我的帐户(自己的登录表单,而不是spotfiy帐户)登录,其他所有人都会登录,无论是哪个浏览器、ip等

我不知道怎么才能解决这个问题。会话id不应该生成随机id吗?有人能帮忙吗

遗漏

            if (session_id() == '') {
                session_id('session1');
            }
无法解决此问题,因为我还需要读取和删除会话中存储的数据。因此,另外,我在这个解决方案中:

    public static function customSessionRead($name)
        {

            if (session_id() == '') {
                session_id('session1');
            }
            session_start();
            session_write_close();

            return $_SESSION[$name];
        }
而且

    public static function customSessionDestroy()
        {
            session_start();
            session_destroy();
        }

如果我做对了。。您的所有用户都获得相同的会话\u id()

所以他们技术上共用一节课。据我所知,如果启动会话,会话_id()将自动生成。因此,您不需要自己设置会话_id()

因此,您的代码应该如下所示:

class SystemHelper
{

    /**
     * if session_id is empty string, then session_id has not been initialized
     * then set session_id named 'session1'
     * start session needs 2 parameters, name and value
     * always close session after writing
     *
     * @param   string  $name   any given name
     * @param   [type]  $value  any given value
     *
     */
    public static function customSessionStore($name, $value)
    {
        session_start();
        $_SESSION[$name] = $value;
        session_write_close();
    }
}
    session_id('session1');

解决了,其实很简单。首先,问题是: 如果这样写:

class SystemHelper
{

    /**
     * if session_id is empty string, then session_id has not been initialized
     * then set session_id named 'session1'
     * start session needs 2 parameters, name and value
     * always close session after writing
     *
     * @param   string  $name   any given name
     * @param   [type]  $value  any given value
     *
     */
    public static function customSessionStore($name, $value)
    {
        session_start();
        $_SESSION[$name] = $value;
        session_write_close();
    }
}
    session_id('session1');
在这两种情况下,customStore和customRead只是意味着恢复会话。当然,无论使用哪种浏览器,ip。。。这就是恢复会议的要点

解决的问题:

    session_create_id($name);
因此,我再次强调:

public static function customSessionStore($name, $value)
{
    // if (session_id() == '') {
    //     session_id('session1');
    // }
    session_create_id($name);
    session_start();
    $_SESSION[$name] = $value;
    session_write_close();
}
以及


感谢您的快速回复,我编辑了我的问题,添加了sessionRead和sessionDestroy;我不能忽略你的建议