0
votes

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

1
Don't directly access $_SESSION. Use CakePHP's session component and helper for that. But I don't see anything that jumps out as the problem in the code that you posted. I would try posting more of your code. Though, just to clarify, when you say "redirect back to the website that had been requested" you're just going between different pages on the same domain, right?Kai
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!hateful

1 Answers

0
votes

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!