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?
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.
For those using Yii2
Yii::$app->user->returnUrl = Yii::$app->request->referrer;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With