E
E
evilelf2015-10-12 17:25:13
Yii
evilelf, 2015-10-12 17:25:13

How to fix 400 error on POST request in yii?

When a POST request occurs, an error 400 occurs.
The whole problem is that when the site has a redirect from / to /ru/
But the request is made to the address: test.ru/ru/page
If you send a regular GET, then everything is fine.
And if POST then 400.
Who faced and how to fix it?
Yii 1.1.16

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
evilelf, 2015-10-12
@evilelf

Defined the problem. I have every POST requires CSRF.
What do you think is the right way to disable requiring CSRF on POST?
Solution:
Make a white list of servers from which you can receive POST without CSRF.
Make a class, inherit CHttpRequest, specify the path to it in the config, and override validateCsrfToken.
I got it like this:

public function validateCsrfToken($event){
        $request = Yii::app()->request;
        if(in_array($_SERVER['REMOTE_ADDR'], $request->whiteListIP)){
            $request->enableCsrfValidation=false;
            return;
        }
        parent::validateCsrfToken($event);
    }

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question