Answer the question
In order to leave comments, you need to log in
Pjax not working in Yii2 due to '\0' character in headers on php 7.0.13?
For pjax to work correctly, you need to have X-Pjax and X-Pjax-Container in the headers.
In \yii\widgets\Pjax, the headers are obtained as follows: $headers = Yii::$app->getRequest()->getHeaders()
If you look in more detail at the getHeaders method in \yii\web\Request, then the headers are obtained using the getallheaders() php function.
So, the problem arose in this place. On a local web server, when developing on PHP 7.0.13, the function returns the correct headers and, accordingly, pjax works correctly. But when the project was transferred to the hosting, pjax stopped working: the response was 200, but the response was empty - and therefore the page was reloaded.
When I started to figure it out and got to the getallheaders() function, it turned out that on the server this function returned an array in which the '\0' character was added to the parameter name.
That is, what should come:
'Accept' => 'text/html, */*; q=0.01'
'X-Requested-With' => 'XMLHttpRequest'
'X-PJAX' => 'true'
'X-PJAX-Container' => '#pjax'
'Accept\0' => 'text/html, */*; q=0.01'
'X-Requested-With\0' => 'XMLHttpRequest'
'X-PJAX\0' => 'true'
'X-PJAX-Container\0' => '#pjax'
Answer the question
In order to leave comments, you need to log in
maybe it's in php, and maybe in the server. Check if pjax sends 'X-Requested-With\0' or 'X-Requested-With'. And then send to regular php without yii and see how it is. You can solve the problem by rewriting the header before including yii.
I would also check php + apache and php + nginx to determine whether the issue is in the server or in php.
The hoster has a new version of php 7.1.0, switched to it, where getallgeader() returns everything correctly without extra characters. On version 7.0.13, the problem remained with them.
Also, on another resource, where I also asked a question, they threw off the link https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=... , there was the same problem for php 5.6.0 and even there is a fix. I'll try to unsubscribe to the hoster, but for myself I consider the problem solved.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question