Codeigniter重复会话问题 [英] Codeigniter duplicate session issue

查看:152
本文介绍了Codeigniter重复会话问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个用codeigniter构建的应用程序,使用sessions类并在数据库中存储会话数据。问题是当我的网页加载一个css文件时,我在数据库中得到额外的会话记录。



直到最近我在一个简单的VPS主机上运行我的应用程序通过rackspace。数据库和Apache都在同一个VPS上运行。不过,我最近将我的应用程式迁移至



任何人都知道可能导致这种情况?谢谢!



更新:
我意识到页面的html可能会有所帮助。注释样式表包括在第13行使问题消失。
http://pastebin.com/iBEb4he6



UPDATE2:

  $ config ['sess_cookie_name'] ='ci_session' 
$ config ['sess_expiration'] = 7200;
$ config ['sess_expire_on_close'] = FALSE;
$ config ['sess_encrypt_cookie'] = FALSE;
$ config ['sess_use_database'] = TRUE;
$ config ['sess_table_name'] ='ci_sessions';
$ config ['sess_match_ip'] = FALSE;
$ config ['sess_match_useragent'] = TRUE;
$ config ['sess_time_to_update'] = 300;

/ *
| ----------------------------------- ---------------------------------------
| Cookie相关变量
| ------------------------------------------ --------------------------------
|
| 'cookie_prefix'=如果您需要避免冲突,请设置前缀
| 'cookie_domain'=设置为.your-domain.com网站范围的Cookie
| 'cookie_path'=通常为正斜杠
| 'cookie_secure'=仅当存在安全HTTPS连接时才设置Cookie。
|
* /

$ config ['cookie_domain'] ='casey.phpfogapp.com'; // $ base_url_parts ['host'];
$ config ['cookie_path'] ='/';

$ config ['cookie_prefix'] =;
$ config ['cookie_secure'] = FALSE;


解决方案

在我的应用程序中,我将以下代码放入.htaccess用于阻止使用css / js / images请求发送Cookie:

 #。htaccess 

#使用Mod_deflate压缩静态文件
< ifmodule mod_deflate.c>
< filesmatch。(js | css | ico | txt | htm | html | php)$>
SetOutputFilter DEFLATE
< / filesmatch>
< / ifmodule>

#加快缓存
FileETag MTime大小

#到期
ExpiresActive开
ExpiresDefault访问加366天

#Future Expires Headers
< filesmatch。(ico | pdf | flv | jpg | jpeg | png | gif | js | css | swf)$>
Header set ExpiresSat,27 Dec 2014 23:59:59 GMT
< / filesmatch>


I have an application built with codeigniter using the sessions class and storing session data in a database. The problem is I'm getting extra session records in my database when my webpage loads a css file.

Up until recently I was running my application on a simple VPS host provided by rackspace. Database and Apache were both running on the same VPS. Recently however I've migrated my application to PHPFog to allow it to scale more easily. I didn't have this issue with my former hosting setup.

The row with the populated value for user_data is my original session. The other three blank sessions are the result of simply refreshing the page three times. I seem to have tracked it down to including a css file in my header, when I comment it out or delete it the issue goes away. It's only this particular css file also, other css/js/image files don't cause this issue.

Here is a link to the css file in question: http://pastebin.com/XfEBNFiC

Anyone know what could be causing this? Thanks!

UPDATE: I realized the html of the page in question might be helpful. Commenting out the stylesheet include on line 13 makes the issue go away. http://pastebin.com/iBEb4he6

UPDATE2:

$config['sess_cookie_name']     = 'ci_session';
$config['sess_expiration']      = 7200;
$config['sess_expire_on_close'] = FALSE;
$config['sess_encrypt_cookie']  = FALSE;
$config['sess_use_database']    = TRUE;
$config['sess_table_name']      = 'ci_sessions';
$config['sess_match_ip']        = FALSE;
$config['sess_match_useragent'] = TRUE;
$config['sess_time_to_update']  = 300;

/*
|--------------------------------------------------------------------------
| Cookie Related Variables
|--------------------------------------------------------------------------
|
| 'cookie_prefix' = Set a prefix if you need to avoid collisions
| 'cookie_domain' = Set to .your-domain.com for site-wide cookies
| 'cookie_path'   =  Typically will be a forward slash
| 'cookie_secure' =  Cookies will only be set if a secure HTTPS connection exists.
|
*/

$config['cookie_domain']    = 'casey.phpfogapp.com'; //$base_url_parts['host'];
$config['cookie_path']      = '/';

$config['cookie_prefix']    = "";
$config['cookie_secure']    = FALSE;

解决方案

In my applications I place the following code into .htaccess for preventing a cookie to be sent with css/js/images requests:

#.htaccess

# Use Mod_deflate to compress static files
<ifmodule mod_deflate.c>
<filesmatch ".(js|css|ico|txt|htm|html|php)$">
SetOutputFilter DEFLATE
</filesmatch>
</ifmodule>

# Speed up caching
FileETag MTime Size

# Expires
ExpiresActive On
ExpiresDefault "access plus 366 days"

# Future Expires Headers
<filesmatch ".(ico|pdf|flv|jpg|jpeg|png|gif|js|css|swf)$">
Header set Expires "Sat, 27 Dec 2014 23:59:59 GMT"
</filesmatch>

这篇关于Codeigniter重复会话问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆