[GH-ISSUE #370] Cypht does not recognize Ajax request under PHP-FPM #316

Closed
opened 2026-02-25 21:34:44 +03:00 by kerem · 8 comments
Owner

Originally created by @fabiomontefuscolo on GitHub (Jan 28, 2020).
Original GitHub issue: https://github.com/cypht-org/cypht/issues/370

Originally assigned to: @jasonmunro on GitHub.

🐛 Bugreport

This is not Cypht bug itself, but a very weird behavior that happens when using PHP-FPM (FastCGI). Probably, it is desired to workaround this to let FastCGI users to use Cypht.

The problem is Cypht is not recognizing Ajax requests as Ajax. Even having HTTP_X_REQUESTED_WITH in the global $_SERVER. That happens because Cypht uses filter_input_array to filter values from from SERVER scope.

From my XDebug terminal:

> $_SERVER['HTTP_X_REQUESTED_WITH']
"xmlhttprequest"

> $_ENV['HTTP_X_REQUESTED_WITH']
"xmlhttprequest"

> filter_input_array(INPUT_SERVER)
array(1)
  PHP_SELF:"/cypht/ajax.php"

filter_input_array behaves like filter_input for this issue.

> filter_input(INPUT_SERVER, 'HTTP_X_REQUESTED_WITH')
null

For some reason, INPUT_ENV works, but I don't think it is reliable.

> filter_input(INPUT_ENV, 'HTTP_X_REQUESTED_WITH')
"xmlhttprequest"

image

image

Version & Environment

Rev: c3fd36ad7b
OS: Linux

Steps to reproduce

  1. Have Cypht running by PHP-FPM
  2. Add IMAP Server
  3. Try deleting an IMAP server
  4. The response in Chrome developer tools should json, but a login form comes
Originally created by @fabiomontefuscolo on GitHub (Jan 28, 2020). Original GitHub issue: https://github.com/cypht-org/cypht/issues/370 Originally assigned to: @jasonmunro on GitHub. ## 🐛 Bugreport This is not Cypht bug itself, but a very weird behavior that happens when using PHP-FPM (FastCGI). Probably, it is desired to workaround this to let FastCGI users to use Cypht. The problem is Cypht is not recognizing Ajax requests as Ajax. Even having `HTTP_X_REQUESTED_WITH` in the global `$_SERVER`. That happens because Cypht uses `filter_input_array` to filter values from from `SERVER` scope. From my XDebug terminal: ``` > $_SERVER['HTTP_X_REQUESTED_WITH'] "xmlhttprequest" > $_ENV['HTTP_X_REQUESTED_WITH'] "xmlhttprequest" > filter_input_array(INPUT_SERVER) array(1) PHP_SELF:"/cypht/ajax.php" ``` `filter_input_array` behaves like `filter_input` for this issue. ``` > filter_input(INPUT_SERVER, 'HTTP_X_REQUESTED_WITH') null ``` For some reason, `INPUT_ENV` works, but I don't think it is reliable. ``` > filter_input(INPUT_ENV, 'HTTP_X_REQUESTED_WITH') "xmlhttprequest" ``` ![image](https://user-images.githubusercontent.com/162023/73302027-b010bf00-41f2-11ea-82e1-bf16f5feeec4.png) ![image](https://user-images.githubusercontent.com/162023/73302149-e5b5a800-41f2-11ea-9dd4-5f10c8a3137d.png) ### Version & Environment Rev: c3fd36ad7b4e50e84d22f9690b971759ef9314e5 OS: Linux ### Steps to reproduce 1. Have Cypht running by PHP-FPM 2. Add IMAP Server 3. Try deleting an IMAP server 4. The response in Chrome developer tools should json, but a login form comes
kerem 2026-02-25 21:34:44 +03:00
Author
Owner

@fabiomontefuscolo commented on GitHub (Jan 28, 2020):

https://bugs.php.net/bug.php?id=49184&thanks=6

<!-- gh-comment-id:579449642 --> @fabiomontefuscolo commented on GitHub (Jan 28, 2020): https://bugs.php.net/bug.php?id=49184&thanks=6
Author
Owner

@jasonmunro commented on GitHub (Feb 6, 2020):

@fabiomontefuscolo sorry for the late follow up, and thanks for the thorough report. Surely we can come up with a work-around. This may not be a Cypht bug, but if a solution can be implemented that isn't too ugly I'm open to it. I will look more closely as soon as I can. Thanks again for the feedback!

<!-- gh-comment-id:582813588 --> @jasonmunro commented on GitHub (Feb 6, 2020): @fabiomontefuscolo sorry for the late follow up, and thanks for the thorough report. Surely we can come up with a work-around. This may not be a Cypht bug, but if a solution can be implemented that isn't too ugly I'm open to it. I will look more closely as soon as I can. Thanks again for the feedback!
Author
Owner

@marclaporte commented on GitHub (Apr 23, 2020):

I wonder if this is issue is present in other operations.

<!-- gh-comment-id:618151331 --> @marclaporte commented on GitHub (Apr 23, 2020): I wonder if this is issue is present in other operations.
Author
Owner

@jasonmunro commented on GitHub (May 5, 2020):

I test this with PHP-FPM 7.4 configured as FastCGI with Nginx and was unable to reproduce. Maybe it was fixed in PHP for 7.4?

<!-- gh-comment-id:624239825 --> @jasonmunro commented on GitHub (May 5, 2020): I test this with PHP-FPM 7.4 configured as FastCGI with Nginx and was unable to reproduce. Maybe it was fixed in PHP for 7.4?
Author
Owner

@fabiomontefuscolo commented on GitHub (May 9, 2020):

Ok! I will run my applications on php 7.4 then. Thank you!

<!-- gh-comment-id:626183502 --> @fabiomontefuscolo commented on GitHub (May 9, 2020): Ok! I will run my applications on php 7.4 then. Thank you!
Author
Owner

@jasonmunro commented on GitHub (May 9, 2020):

@fabiomontefuscolo make sure you are on the latest master git checkout as I have made a number of PHP 7.4 specific fixes lately.

<!-- gh-comment-id:626242017 --> @jasonmunro commented on GitHub (May 9, 2020): @fabiomontefuscolo make sure you are on the latest master git checkout as I have made a number of PHP 7.4 specific fixes lately.
Author
Owner

@marclaporte commented on GitHub (May 10, 2020):

hmmm. I think we should support PHP 7.2, 7.3 and 7.4 as per https://www.php.net/supported-versions.php

<!-- gh-comment-id:626253745 --> @marclaporte commented on GitHub (May 10, 2020): hmmm. I think we should support PHP 7.2, 7.3 and 7.4 as per https://www.php.net/supported-versions.php
Author
Owner

@jasonmunro commented on GitHub (May 11, 2020):

@marclaporte We do as evidenced here: https://travis-ci.org/github/jasonmunro/cypht
However as the OP pointed out, the fact that request headers are being dropped from the built in SERVER array under this specific configuration is a bug in PHP and not something we can easily (or safely) work around. If this continues to be a problem we can re-address it, however it's possible a fix was made and backported to PHP 7.* so for now I'm comfortable with the solution being "upgrade to PHP 7.4 if you are using FastCGI via FPM, or use a different interface to PHP"

<!-- gh-comment-id:626782305 --> @jasonmunro commented on GitHub (May 11, 2020): @marclaporte We do as evidenced here: https://travis-ci.org/github/jasonmunro/cypht However as the OP pointed out, the fact that request headers are being dropped from the built in SERVER array under this specific configuration is a bug in PHP and not something we can easily (or safely) work around. If this continues to be a problem we can re-address it, however it's possible a fix was made and backported to PHP 7.* so for now I'm comfortable with the solution being "upgrade to PHP 7.4 if you are using FastCGI via FPM, or use a different interface to PHP"
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/cypht#316
No description provided.