duanfei8897 2013-10-04 21:24
浏览 64
已采纳

CodeIgniter会话与cookie

I have an application which is under development in CodeIgniter. But I have a problem with session management. By default, sessions in CodeIgniter are saved onto the visitor's machine, which means they last about two hours without being deleted on the close action (visitor closing the browser); while all of us know that PHP keeps session as long as the browser runs, and as it is closed by the user, it will kill it.

My problem: I love CI session style, but for some particular purposes and in some instances I need PHP session style (being deleted when browser is closed). CI provides me such option but I do not like to delete all sessions when the browser is closed. I need only two or three session values to be removed on browser shut down. Should I use go back to PHP pure session for the instances where sessions must be delete on browser shut down? Or CI has some options for customizing the lifespan of session for individual vlaues?

thanks in advance

  • 写回答

1条回答 默认 最新

  • dscdttg4389 2013-10-04 21:30
    关注

    You can change/set the value of sess_expiration config variable in the file application/config/config.php - the default is 7200 seconds (2 hrs). Set it to zero to never expire. Another useful variable is sess_expire_on_close. More details at http://ellislab.com/codeigniter/user-guide/libraries/sessions.html

    If you want to customize across different types of sessions, you can create your own Session class based on CI code, you can create a new class or extend class CI_Session and just make it read from a different set of config variables. https://github.com/EllisLab/CodeIgniter/blob/develop/system/libraries/Session/Session.php

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计