PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Saturday, March 19, 2022

[FIXED] $this->redirect showing data in url

 March 19, 2022     redirect, url, yii     No comments   

Issue

I am using $this->redirect to redirect from one action to another

$this->redirect(array('site/payment','bookingID'=>$bookingID,'orderID'=>$model->quoteNo,'amount'=>$rent));

But I don't why it showing parameter in url

https://www.siteurl.com/bookingID/5/orderID/123456/amount/220.00

How do I hide my data from user?


Solution

You can do it using sessions. You can access current Session with Yii::$app->session. You can send those parameters in session.. For Example

public function actionOne() {
    // Check if the Session is Open, and Open it if it isn't Open already
    if (!Yii::$app->session->getIsActive()) {
        Yii::$app->session->open();
    }
    Yii::$app->session['bookingID'] = $bookingID;
    Yii::$app->session['orderID'] = $model->quoteNo;
    Yii::$app->session['amount'] = $rent;
    Yii::$app->session->close();
    $this->redirect(['site/payment']);
}

public function actionTwo() {
    // Then you can get those values like this...
    $bookingID= Yii::$app->session['bookingID'];
    $orderID= Yii::$app->session['orderID'];
    $amount= Yii::$app->session['amount'];
   // do whatever you want..
}


Answered By - Asfandyar Khan
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home
View mobile version

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing