How to set returnUrl value in Yii

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

How can I set its value for the page that requested the current page, since I don’t know from which page the user visited the current page?

+4
source share
7 answers

You can use Yii::app()->request->urlReferrerto find out 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 third-party site, then this will redirect them from your site.

+7
source

There is no such thing as: Yii::app()->user->urlReferrer

It should be: Yii::app()->request->urlReferrerorYii::app()->request->requestUri (current page)

So try the following:

Yii::app()->user->returnUrl = Yii::app()->user->urlReferrer;

( ):

Yii::app()->user->returnUrl = Yii::app()->request->requestUri;
+3

, Yii2

Yii::$app->user->returnUrl = Yii::$app->request->referrer;
+3

Yii URL-, : https://github.com/cornernote/yii-return-url#yii-returnurl

, Yii , url GET/POST SESSION. , , URL- .

+2

$http = new CHttpRequest();
$referrer_url = $http->getUrlReferrer();
$this->redirect($referrer_url);

,

0

Yii::app()->user->returnUrl = Yii::app()->request->urlReferrer;
$this->redirect(Yii::app()->user->returnUrl);
0

, : $referer, Login Yii::$app->request->referrer, , , , null, index. , URL- , , , , URL-, $this->goBack($form->referer? $form->referer: null). :

:

public $referer;

:

$model = new Login();
$model->referer = Yii::$app->request->referrer;
...
if($model->load(Yii::$app->request->post()){
    ...
    if($model->save()){
        return $this->goBack((($model->referer) ? $model->referer : null));
    }
}

login.php:

<?= $form->field($model, 'referer')->hiddenInput()->label(false) ?>
0

All Articles