[PHP-DEV] Command line argument, that trates as QUERY_STRING, isn't proper. From: Akihiro Sagawa (sagawa <email protected>)
Date: 02/22/01

Hi,

I get funny $HTTP_GET_VARS passed by command line argument query_string,
on PHP 4.0.3(as far as I know :) with cgi-sapi.

This is sample for this problem.
test.php is <?php var_dump($HTTP_GET_VARS); ?>
and run from command line.

% php -f test.php 'AAA=xx&BB=yy' 'CC=zz'
array(2) {
  ["test_php_AAA"]=>
  string(2) "xx"
  ["BB"]=>
  string(8) "yy CC=zz"
}

`AAA' is connected with file name,
and inserted space between arguments.
(test.php was changed to test_php because of php variable name restriction.)

So, I modify sapi/cgi/cgi_main.c.
It provides this which I wanted.

% php -f test.php 'AAA=xx&BB=yy' 'CC=zz'
array(3) {
  ["AAA"]=>
  string(2) "xx"
  ["BB"]=>
  string(2) "yy"
  ["CC"]=>
  string(2) "zz"
}

How about this? :-)

This is patch for the problem.
% diff -u cgi_main.c~ cgi_main.c
--- cgi_main.c~ Sun Dec 3 10:09:13 2000
+++ cgi_main.c Thu Feb 22 21:20:47 2001
@@ -649,14 +649,10 @@

                        s = malloc(len + 1); /* leak - but only for command line version, so ok */
                        *s = '\0'; /* we are pretending it came from the environment */
- if (script_file) {
- strcpy(s, script_file);
- strcat(s, "+");
- }
                        for (i = ap_php_optind, len = 0; i < argc; i++) {
                                strcat(s, argv[i]);
                                if (i < (argc - 1)) {
- strcat(s, "+");
+ strcat(s, PG(arg_separator));
                                }
                        }
                        SG(request_info).query_string = s;

and, Thank you for reading my poor English. ;)

dewa-dewa. (in Japanese :)

-- 
Akihiro SAGAWA <sagawa <email protected>>

-- PHP Development Mailing List <http://www.php.net/> To unsubscribe, e-mail: php-dev-unsubscribe <email protected> For additional commands, e-mail: php-dev-help <email protected> To contact the list administrators, e-mail: php-list-admin <email protected>