In Yii, while looking at the source code for CWebUser::logout, I've noticed that they use Yii::app()->getSession()->destroy()
instead of the usual PHP session_destroy
.
Doing a bit of research I saw that Yii has a class called CHttpSession
with its own methods to store data.
This got me thinking - are they cross-compatible? Is CHttpSession
just a nice wrapper? Or is it an all or nothing process?
In my custom code, I've been using $_SESSION
to do all of my session-related stuff. While in things generated by Yii, I assume that it uses CHttpSession
. Is it a problem to use both and mix them up?
I am now in the process of moving my session handling to AWS DynamoDB ( https://github.com/aws/aws-sdk-php/blob/master/docs/feature-dynamodb-session-handler.rst ), and before I add this additional layer, I want to make sure everything is compatible.
You can use Database based session to recover that. Its really simple. Just put
'session' => array(
'class'=>'CDbHttpSession',
'connectionID' => 'db'
),
on config/main.php components
CHttpSession
is a nifty OO wrapper for php sessions. The underlying implementation uses php's session methods. Here's a snippet of part of the code for CHttpSession::open()
:
public function open()
{
if($this->getUseCustomStorage())
@session_set_save_handler( array($this,'openSession'),array($this,'closeSession'),array($this,'readSession'),array($this,'writeSession'),array($this,'destroySession'),array($this,'gcSession'));
@session_start();
For Yii convention, always use CHttpSession
instead of $_SESSION
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.