作者:顾世嵐 | 来源:互联网 | 2014-03-27 00:19
Zend_Session 和Zend_Session_Namespace可以提供一组最可靠、安全的处理会话相关的功能,使用起来也是相当简单,每个Zend_Session_Namespace的
Zend_Session 和Zend_Session_Namespace可以提供一组最可靠、安全的处理会话相关的功能,使用起来也是相当简单,每个Zend_Session_Namespace的实例对应于$_SESSION全局数组的一个条目。
下面看看php教程实例:(简单的用户登录和退出)
render("index");
}
public function loginAction(){
$username = $this->getRequest()->getParam('username');
$password = MD5($this->getRequest()->getParam('password'));
if($username != '' && $password != ''){
$table = new Admin();
$db = $table->getAdapter();
$where = $db->quoteInto('username = ?', $username)
. $db->quoteInto('AND password = ?', $password);
$users = $table->fetchAll($where)->toArray();
if(count($users)>0){
$session = new Zend_Session_Namespace('admin');
//$session->uid = $users[0]['uid'];
$session->username = $users[0]['username'];
$this->view->username = $session->username;
$this->_forward('index','index');
}else{
$this->view->mes = "用户名或密码错误";
$this->_forward('err','global');
}
}else{
$this->_forward('err','global');
}
}
public function loginoutAction(){
$session = new Zend_Session_Namespace('admin');
$session->__unset("admin");
$this->_forward('index','index');
}
}
?>
如果想移出该session中所有变量可用 $session->unsetAll();