简体   繁体   中英

encrypt parameter in URL setting in main.php yii?

Here problem is with encrypt code in the url,

My url is this and encrypt code is at the last:

http://localhost/php_pro_106/reload/ByCustomer/mJYwIzoaIGe0R8lAVCqPhG%2Fg0jJFWjiWWdPnkq5VDlY%3D

In main.php Url settings:

'urlManager'=>array(
     'urlFormat'=>'path',
     'showScriptName' => false,
      'caseSensitive'=>false,
        'rules'=>array(
            'giftcard/<id:\w+>'=>'giftcard/index',
            'reload/ByCustomer/<giftcode:\w+>'=>'reload/ByCustomer',

             '<controller:\w+>/<id:\d+>'=>'<controller>/view',

           '<controller:\w+>/<action:\w+>/<id:\w+>'=>'<controller>/<action>',
            '<controller:\w+>/<action:\w+>'=>'<controller>/<action>',

           ),
    ),

my action is in reload controller:

public function actionByCustomer()
  {

    echo "test";
    print_r($_GET);
    }

I am getting:

The requested URL     /localhost/reload/ByCustomer/mJYwIzoaIGe0R8lAVCqPhG/g0jJFWjiWWdPnkq5VDlY= was    
not found on this server.

Actually problem is with ByCustomer/mJYwIzoaIGe0R8lAVCqPhG%2Fg0jJFWjiWWdPnkq5VDlY%3D as it is encrypt.What Should I do to make it work?

In your byCustomer rule the giftcodes regex matches on words. But that uri part mJYwIzoaIGe0R8lAVCqPhG%2Fg0jJFWjiWWdPnkq5VDlY%3D is not a word since it contains chars like %. It looks like an url encoded string, the %2f would be a / and the %3d a = . However all these chars a not in a word.

Try this rule:

'reload/ByCustomer/<giftcode:.+>'=>'reload/ByCustomer',

It matches any character after reload/ByCustomer/ which looks okay for your purpose.

I got the solution of it,For that I have to change my encode and decode method:

The problem was due to some characters which are there in encoded Url.So, I have to replace these characters.

In main.php Url Manager will be like:

  'reload/ByCustomer/<giftcode>'=>'reload/ByCustomer',

The apache has problem with %2F in URL, it will always reply with 404, php script is not executed.

EDIT:

There's a solution, but it requires you can edit apache configuration file for your virtual host at least (I didn't have that at that time). Then you have to add AllowEncodedSlashes On inside your <VirtualHost> . Or you can also set it globally.

If you dont want to do this.

These links Help me:

Stack over flow Solution1

Stack over flow solution2

google group

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM