Cameron
Cameron

Reputation: 28803

CakePHP Check referer

I have the following code in my CakePHP app home controller:

public function index ()
{
    if($this->referer(array('controller' => 'users', 'action' => 'logout')))
    {
        $this->layout = 'splash';

        $this->set('title_for_layout', 'Goodbye');

        $this->render('loggedout');
    }
    else
    {
        if (!$this->Auth->user())
        {
            $this->layout = 'splash';

            $this->set('title_for_layout', 'Welcome to CreatHive');

            $this->render('splash'); 

        }
        else
        {

            $this->layout = 'home';

            $this->set('title_for_layout', 'CreatHive');

            $this->render('index');

        }
    }
}

Basically it says if the user came from the logout action show the loggedout view but if not then check if they are logged in and either show the splash page or home page.

However it ALWAYS shows the logged out view regardless of being logged in or not or even coming from the logout action (even flushing sessions/cookies etc doesn't work)

Any ideas what the problem is as the code looks fine to me :/

Thanks

Upvotes: 2

Views: 5630

Answers (1)

Tyler
Tyler

Reputation: 2126

Change:

if($this->referer(array('controller' => 'users', 'action' => 'logout')))

To:

if($this->referer() == Router::url(array('controller' => 'users', 'action' => 'logout')))

Upvotes: 4

Related Questions