How to set returnUrl value in Yii

Let me see picture Let me see · Nov 30, 2013 · Viewed 16.8k times · Source

I am using Yii and the problem I am getting is with the Yii::app()->user->returnUrl. It always returns me to the index.php page.

How can I set its value to the page which requested the current page as I do not know from which page user has visited the current page?

Answer

Keilo picture Keilo · Nov 30, 2013

You can use Yii::app()->request->urlReferrer to see where the user came from.

public function beforeAction()
{
    Yii::app()->user->returnUrl = Yii::app()->request->urlReferrer;
    return parent::beforeAction();
}

Be careful, if the user came from a 3rd party site, then this will redirect them away from your site.