Cameron
Cameron

Reputation: 28803

CakePHP check referer

I have the following code:

function success()
    {
        if(!$this->referer(array('controller'=>'contact','action'=>'index')))
        {
            $this->redirect(array('controller'=>'contact','action'=>'index'));
        }
    }

I'm trying to check if the user has accessed the success page from the index action and if not then send them back to the index method so they can't view the success page if they haven't previously submitted some data on the index action.

It doesn't work however as the user can still visit the success page even if they haven't visited the index page first...

Can anyone help? Thanks

Upvotes: 2

Views: 8517

Answers (3)

Maki
Maki

Reputation: 31

try to add true on the end of Router::url, function to get full url:

if($this->referer() != Router::url(array('controller'=>'contact','action'=>'index'),true))

Upvotes: 3

Henri
Henri

Reputation: 740

I guess that won't work like that. You are now just setting default referer with that code. Try something like:

if($this->referer() != Router::url(array('controller'=>'contact','action'=>'index')))

Edit: corrected the code

Upvotes: 1

Cameron
Cameron

Reputation: 28803

function success()
{
    if($this->referer() != Router::url(array('controller'=>'contact','action'=>'index')))
    {
        $this->redirect(array('controller'=>'contact','action'=>'index'));
    }
}

Upvotes: 3

Related Questions