简体   繁体   中英

redirect losses session cakephp

I'm trying to save the session in a variable url which the user tries to enter, if the user is not logged in, so I redirect to the login URL and once it has been logged successfully redirect back to the website that had requested. My problem is that it does not save the session variable or from one side or the other.

This in appController

if($this->action!='logout' && $this->action!='logout_cas' && $this->action!='login_cas' && $this->action!='login'){
        if(isset($_SESSION['cas_user'])){
            $_SESSION['url_user'] = Router::url('', true);
            $this->redirect(array('controller'=>'users','action'=>'login_cas'));
        }
    }

This in UsersController in function login_cas

if ($this->Auth->user('active') != '1') {
                $active = $this->Auth->user('active');
                $this->Session->destroy();
                if($active < 0)
                    throw new Exception(__('Invalid user or password. Try again'));

                throw new Exception(__('User blocked, contact your administrator'));
            } else {
                $_SESSION["user_login_errors"] = 0;
                //$this->redirect(array('controller'=>'users','action'=>'home'));
                $this->redirect($_SESSION['url_user']);
            }

Message Notice (8): Undefined index: url_user

Of course, only my domain web pages. The problem was solved, my code worked perfect in other repositories, clone the site and returned to work again. Anyway take your advice and Takes

$this->Session->write

and read CakePHP. Thnks!

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM