我正在使用 Yii 构建一个 SOAP Web 服务,并且我正在尝试通过会话 ID 管理身份验证,但它会随着每个请求而不断变化。
这是我写的代码:
class MessagingController extends CController {
public function login($username, $password) {
$user = User::model()->find('username=:username AND password=:password', array(':username' => $username, ':password' => $password));
if($user) {
$session = new Session();
$session->id = Yii::app()->session->sessionID;
$session->user = $user->id;
$session->start = date('Y-m-d H:i:s', time());
$session->duration = $this->sessionDuration; //Session duration is 1hr.`
return $session->save() ?
$this->generateResponse(0, 'Session initiated successfully.', array('SessionId' => $session->id, 'Timestamp' => $session->start, 'Duration' => $session->duration)) : generateResponse(-1, 'Server error. #S', null);
}
return $this->generateResponse(-1, 'Unknown User. #UU', null);
}
}
配置文件:
'session' => array('autoStart' => true, 'timeout' => 1440, 'cookieMode' => 'allow', ),