$ _GET and $ _POST variables do not exist when using the lighttpd web server

I installed the lighttpd web server on my windows computer and I have a problem: the $_GET and $_POST variables are not defined in the PHP files.

For example, I have this simple script ( tmp.php ):

 <?php echo "x: '" . $_GET ['x'] . "'<br />"; ?> 

When I go to the address: http://localhost/tmp.php?x=123

I get this error message:

 Notice: Undefined index: x in /srv/www/htdocs/tmp.php on line 3 x: '' 

While I put the same file on shared hosting, I get:

 x: '123' 

Also php command:

 empty ($_GET) 

returns true.

Same for all $ _POST variables.

Is there a wrong configuration in my php.ini ?

Command:

 print_r($_SERVER); 

gives the following result:

 Array ( [SERVER_SOFTWARE] => lighttpd/1.4.20 [SERVER_NAME] => localhost [GATEWAY_INTERFACE] => CGI/1.1 [SERVER_PROTOCOL] => HTTP/1.1 [SERVER_PORT] => 80 [SERVER_ADDR] => 0.0.0.0 [REQUEST_METHOD] => GET [REDIRECT_STATUS] => 200 [QUERY_STRING] => x=123 [REQUEST_URI] => /tmp.php?x=123 [REMOTE_ADDR] => 127.0.0.1 [REMOTE_PORT] => 3150 [CONTENT_LENGTH] => 0 [SCRIPT_FILENAME] => /srv/www/htdocs/tmp.php [SCRIPT_NAME] => /srv/www/htdocs/tmp.php [DOCUMENT_ROOT] => [SYSTEMROOT] => C:\WINNT [HTTP_ACCEPT] => */* [HTTP_ACCEPT_LANGUAGE] => en-gb [HTTP_USER_AGENT] => Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; .NET CLR 1.0.3705; .NET CLR 1.1.4322; .NET CLR 2.0.50727; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729; InfoPath.1) [HTTP_ACCEPT_ENCODING] => gzip, deflate [HTTP_HOST] => localhost [HTTP_CONNECTION] => Keep-Alive [WINDIR] => C:\WINNT [PHP_SELF] => /srv/www/htdocs/tmp.php [PATH_TRANSLATED] => /srv/www/htdocs/tmp.php [REQUEST_TIME] => 1328287189 [argv] => Array ( [0] => /srv/www/htdocs/tmp.php ) [argc] => 1 ) 

So, the value x=123 exists in $_SERVER['QUERY_STRING'] and in $_SERVER['REQUEST_URI'] , but I donโ€™t know how to get it.

+6
source share
3 answers

First, make sure we have something missing.

try it

 <?php // test1.php print('GET: '); // First missing semicolon print_r($_GET); print('HTTP_GET_VARS: '); // Second missing semicolon print_r($HTTP_GET_VARS); ?> 

Second try $ _POST

Make a simple html form and try to publish it.

 <?php // test2.php print_r($_POST); ?> <form method="POST"> <input type="text" name="myvar" /> <input type="submit""/> </form> 

I know these sounds are stupid, but please try them so we can exclude them.

Finally, do you use rewrite rules?

Check out lighttpd.conf for any mention of url.rewrite. Lighttpd does not try to guess a URL such as apache, you need to specify that it include a query string if you use rewriting. For example (important bits are shown in bold - add them to your rewrites).

url.rewrite = ("^ / ([az] +) / ([az] +) (\? *) (. *) " => "/index.php?controller=$1&action=$2& $ 4 )

+2
source

According to the docs, this can be caused by setting php.ini variables_order .

The default value is EGPCS , but if it was somehow changed and did not contain the letter G, the GET variables would be completely ignored and $_GET would be empty.

+1
source

Well, as far as I can see, the length of the content is zero, it should not be "zero". Install the script and verify that the header was sent during the request and check the response header. It seems like there should be a headline.

Hi

0
source

Source: https://habr.com/ru/post/907591/


All Articles