Coder Social home page Coder Social logo

Comments (7)

qidizi avatar qidizi commented on September 23, 2024

另一个方法是load后再 session->xxyy = n秒后过期,

from codeigniter.

qidizi avatar qidizi commented on September 23, 2024

还有就是update也会导致这个问题,本来我set时,设置n秒后失效(但是config.php中设置是close后失效),那么达到刷新时间了,它就会load config.php来重新setcookie....这时update就会导致前面设置的失效时间全部乱完了......
目前我想法是,要么在database中保存这个时间,要么,直接禁用update方法....

from codeigniter.

hex-ci avatar hex-ci commented on September 23, 2024

提交个补丁看看吧~哈哈

from codeigniter.

qidizi avatar qidizi commented on September 23, 2024

补丁也没有什么,就是逻辑上来说是有问题的.

getcookie时

$this->load->lib('session');时加载了config.php中的session的相关配置了.
这时的过期时间什么的都是没有什么作用的对于取来说.

接着再发生set_userdata时,因为这里不提供关于过期或是其它的setcookie本身提供的配置参数.所以,没办法传入.那set_userdata就只能是 name与value了.
同时比较麻烦的是这时再load->lib('session',$myConfig)是不起作用的.话说,也不应该出现多个类的实例.除非有必要.

那么我的想法是在set_userdata时能使用config,来达到改变时间和domain之类setcookie本身支持的参数,本来就应该是这样....那有init时就能配置所有的参数哦?

再有它的定时update也是一个问题,在set时没有记录过期时间与domain之类值,那么,自动的处理resetcookie肯定就是直接的使用config.php中的配置了.但是如果我的当时set_userdata使用是n个小时过期和path是xxyy呢?它没记住,就直接使用了config.php的配置了?
目前我的需求上,不需要这样考虑这个安全问题.就直接的禁用了这个方法.

反正,既然重写这个了功能,应该完全的按照setcookie的原生逻辑来实现就可以了.然后再在某些方面提高一下安全才对.现在这个session乱来,不实用.

<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class MY_Session extends CI_Session {
    public function __construct($params = array())  {
        parent::__construct($params);
    }

    //ci的set有问题,如果已经创建实例,就会导致set的配置不被使用,因为不再new了.所以这里改变它的config
    function _set_userdata($newdata = array(),$config=null) {
        if (is_array($config)) {
            foreach (array('sess_encrypt_cookie', 'sess_use_database', 'sess_table_name', 'sess_expiration', 'sess_expire_on_close', 'sess_match_ip', 'sess_match_useragent', 'sess_cookie_name', 'cookie_path', 'cookie_domain', 'cookie_secure', 'sess_time_to_update', 'time_reference', 'cookie_prefix', 'encryption_key') as $key)
            {
                if (isset($config[$key]))
                    $this->$key = $config[$key];
            }
        }

        return $this->set_userdata($newdata);
    }

    //重写,禁用这个方法:因为达到更新时间,就会load config.php中的seesion配置来setcookie,这时会导致过期时间变成了config.php中的配置,
    //当前面setcookie时定义了这个时间时,就会乱套了....
    function sess_update() {        
    }
}

from codeigniter.

hex-ci avatar hex-ci commented on September 23, 2024

我觉得你对 Session 的理解有偏差,Session 本身就应该在浏览器关闭后就失效,考虑什么是“会话”。
虽然这里 CI 使用 Cookie 实现 Session,但是“会话”的本意不能丢掉。
如果想保存几天,那是 Cookie,请用 Cookie 实现这个功能。

from codeigniter.

qidizi avatar qidizi commented on September 23, 2024

嗯,这么说,确实是

from codeigniter.

hex-ci avatar hex-ci commented on September 23, 2024

有想法的话,可以随时 push patch,我们会提交给 CI 官方的。

from codeigniter.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.