$_GET, $_POST and $_REQUEST not being populated

2019-07-18 03:17发布

问题:

I inherited an XP machine with xitami/pro server running on it and installed PHP 5.2.17 because I thought I might need the VC6 version.

PHP works and the phpinfo shows as it should. When I do www.domain.com/test.php?x=y&z=test the $_GET is not being populated.

The $_REQUEST variable is not being populated either. If I post it in a form and post it, the $_POST is empty as is the $_REQUEST.

If I loop through the $_SERVER variables and display them on a get, the QUERY_STRING is populated with the get variables.

When I do a print_r on any of the variables, it is empty. I get: Array ( ) 1

I then upgraded to PHP 5.4 and the same thing.

What is the problem? I am at a loss and don't know what else to try.

回答1:

I would suspect this problem arises when the server is configured wrong. Especially when the wrong SAPI is used (for example, I'm pretty sure $_GET/$_POST are not available when using the PHP CLI.

To see if this causes your issue, create a new php file, and insert the following

<?php
  echo php_sapi_name();
?>

In case this returns CLI I'm pretty sure that causes your issues. Solve it by configuring your server to use the correct SAPI.

TL;DR:
I assume you're using C:\php\php.exe as your PHP interpreter. Try C:\php\php-cgi.exe instead.



标签: php post get