Comments (7)
另一个方法是load后再 session->xxyy = n秒后过期,
from codeigniter.
还有就是update也会导致这个问题,本来我set时,设置n秒后失效(但是config.php中设置是close后失效),那么达到刷新时间了,它就会load config.php来重新setcookie....这时update就会导致前面设置的失效时间全部乱完了......
目前我想法是,要么在database中保存这个时间,要么,直接禁用update方法....
from codeigniter.
提交个补丁看看吧~哈哈
from codeigniter.
补丁也没有什么,就是逻辑上来说是有问题的.
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.
我觉得你对 Session 的理解有偏差,Session 本身就应该在浏览器关闭后就失效,考虑什么是“会话”。
虽然这里 CI 使用 Cookie 实现 Session,但是“会话”的本意不能丢掉。
如果想保存几天,那是 Cookie,请用 Cookie 实现这个功能。
from codeigniter.
嗯,这么说,确实是
from codeigniter.
有想法的话,可以随时 push patch,我们会提交给 CI 官方的。
from codeigniter.
Related Issues (20)
- Cannot redeclare class ci_exceptions HOT 16
- codeigniter如何以RDS方式连接数据库呢 HOT 4
- base_url 不定义时某些情况下 redirect 到 https HOT 1
- 继承类的权限判断后中止执行并提示的需求 HOT 2
- CI不能被类include方式使用 HOT 4
- 关于input类的“不可见字符”被屏蔽的问题 HOT 2
- contoller repeat 2times 默认控制器重复执行 HOT 12
- I can not understand the "helper" function
- form_dropdown HOT 1
- smtp发中文内容乱码问题 HOT 1
- 校验提交的数组数据时的问题
- helper函数“download”在IE下下载中文文件乱码
- codeigniter 连接远程oracle HOT 2
- Message: mysql_errno(): XXX is not a valid MySQL-Link resource HOT 1
- default_controller is not working when enable_query_strings is enabled HOT 1
- session 设置memcached 驱动, 无法保存session
- CI default_controller setting HOT 1
- DB class trouble with pcntl
- PHP如果使用了ZendGuadLoader后CI加载session类会导致服务器500错误 HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from codeigniter.