I am learning Zend Framework and having issues with Zend_Session_Namespace.
Here is the scenario:
- Homepage(user clicks on login-Index Controller)
- login page(user auth is done->Login Controller)
- On Successful login: Create a new zend_Session_Namespace("login") and take him to another page with home page button.
- User Clicks the Home Page Button.I can Access the username from the session and display the welcome message.
User again clicks on the login page. I am checking isset($session->name) to prevent login again and take him to other page instead. --> I am failing here . The session is somehow reset , I am quite unsure what I am missing.
class IndexController extends Zend_Controller_Action { public function init() { } public function indexAction() { $session = new Zend_Session_Namespace("login_session"); //Check if the session is already valid if(isset($session->name)) { $this->view->userLoggedIn="true"; $this->view->name=$session->name; } } } class LoginController extends Zend_Controller_Action { public function loginaction(){ $session = new Zend_Session_Namespace("login_session"); if(isset($session->name)){ //Redirect to New Page-Already Logged In } else { //Authenticate the user and if login is successful $session->name="USER_NAME"; } } }
Thank You.