K
K
koa_t2016-12-05 11:10:32
Yii
koa_t, 2016-12-05 11:10:32

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'

And comes:
'Accept\0' => 'text/html, */*; q=0.01'
 'X-Requested-With\0' => 'XMLHttpRequest'
 'X-PJAX\0' => 'true'
 'X-PJAX-Container\0' => '#pjax'

The hosting also has PHP version 7.0.13. In addition, later versions of php (5.4, 5.6) were tested on the same hosting and on different orders - pjax works and the headers are normal, i.e. does not work exactly with php 7.0.13 (looked at different orders). I also tested yii2 and pjax on a completely different hosting with the same version of php and everything works there.
That is, the problem is in the php itself on this hosting?
Written off with technical support. They shrug their shoulders and say that there is little information and it is necessary to provide requirements for the php specification.
Advise where to look? What exactly should be the requirements, because, as I understand it, this concerns some global php settings? In principle, the problem is solved by a simple str_replace, but this is a change in the main files of the framework itself, and this is not good in general, and in particular I would like to be able to update yii.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Maxim Timofeev, 2016-12-05
@webinar

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.

K
koa_t, 2016-12-06
@koa_t

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 question

Ask a Question

731 491 924 answers to any question