dream2891 2015-03-22 09:26
浏览 71

PHP在同一个域上的不同会话ID

I created a simple session class that handles sessions. However I am encountering big problems with the session_id.

small note: it happens to go just well for a couple of weeks. and all of a sudden it stops working

What's the case :

http://domain1.com/framework/start/

Has the following Session ID: svplf2tln1j05n75jbokcmhfo3

http://domain1.com/framework/login/

Has the following Session ID: njlqg0jomo00r560bp6k0pje55

This is strange.

But important to know my settings:

            ///######## IF A SESSION COOKIE SHOULD BE SET
        if(self::$setsessioncookie === true){
            ///######## SETTINGS ARRAY
            $SessionSettings = array(
                                        'session.cookie_lifetime'       =>          self::$limit,           /// **** LIFETIME OF THE SESSION COOKIE (in seconds)
                                        ///'session.cookie_path'           =>          self::$path,         /// **** THE DOMAIN FOR WHERE THE COOKIE WILL WORK. (single /  for all paths on the domain.)
                                        'session.cookie_domain'         =>          self::$domain,          /// **** DEFINE THE DOMAIN NAME
                                        'session.cookie_secure'         =>          self::$secure,          /// **** ONLY BY SECURE CONNECTIONS
                                        'session.cookie_httponly'       =>          self::$httponly         /// **** INDICATE THAT THE SESSION COOKIE IS AVAILABLE THROUGH HTTP PROTOCOLS ONLY (not by Javascript)
                                    );
            ///########==================================================
            ///######## SET THE SESSION COOKIE PARAMETERS
            ///########==================================================
            ///######## RUN THROUGH ALL SETTINGS
            foreach($SessionSettings as $Option => $Setting){
                ///######## IF THE OPTION IS NOT EMPTY
                if($Setting !== NULL){
                    ///######## SET THE SETTING
                    ini_set($Option, $Setting);
                }
            }

As you see I commented out :

'session.cookie_path'           =>          self::$path

So it should not be limited to one path only. But the problem still occurs.

Before doing this I set a session cookie:

///########==================================================
///######## STORING THE SESSION ID IN A COOKIE
///########==================================================
setcookie(
            self::$SessionName,             /// **** SET THE COOKIE NAME
            session_id(),                   /// **** SET THE COOKIE CONTENTS
            (time() + self::$limit)         /// **** MAX DURATION OF THE COOKIE LIFETIME
        );
///########==================================================

Or should I do this before setting the ini_set??

Small update: I have the FireFox webdeveloper extension installed and when I click: "Delete path cookies" the system logs out and allows me to login properly.

This could indicate that the path has been set? But I have commented this one out???

Maybe I should set the path but specify the depth?? for example ini_set('session.cookie_path', 'http://domain1.com/*')?

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥20 测距传感器数据手册i2c
    • ¥15 RPA正常跑,cmd输入cookies跑不出来
    • ¥15 求帮我调试一下freefem代码
    • ¥15 matlab代码解决,怎么运行
    • ¥15 R语言Rstudio突然无法启动
    • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
    • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
    • ¥15 用windows做服务的同志有吗
    • ¥60 求一个简单的网页(标签-安全|关键词-上传)
    • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法