]> granicus.if.org Git - php/commitdiff
Fixed a bug in $argv and $argc not being properly defined in command-line mode
authorZeev Suraski <zeev@php.net>
Mon, 6 Nov 2000 09:55:53 +0000 (09:55 +0000)
committerZeev Suraski <zeev@php.net>
Mon, 6 Nov 2000 09:55:53 +0000 (09:55 +0000)
@- Fixed a bug that prevented $argv and $argc from being defined in the command
@  line version of PHP (Stas)

sapi/cgi/cgi_main.c

index 01ca27fdbea854389f94b1f5c5c442b00633680d..c320fa289147021207fb8c8acec60229b9fd8006 100644 (file)
@@ -645,6 +645,25 @@ any .htaccess restrictions anywhere on your site you can leave doc_root undefine
        EG(interactive) = interactive;
 #endif
 
+       if (!cgi) {
+               if (!SG(request_info).query_string) {
+                       for (i = ap_php_optind, len = 0; i < argc; i++) {
+                               len += strlen(argv[i]) + 1;
+                       }
+
+                       s = malloc(len + 1);    /* leak - but only for command line version, so ok */
+                       *s = '\0';                      /* we are pretending it came from the environment  */
+                       for (i = ap_php_optind, len = 0; i < argc; i++) {
+                               strcat(s, argv[i]);
+                               if (i < (argc - 1)) {
+                                       strcat(s, "+");
+                               }
+                       }
+                       SG(request_info).query_string = s;
+               }
+       }
+
+
        if (!cgi_started) {
                if (php_request_startup(CLS_C ELS_CC PLS_CC SLS_CC)==FAILURE) {
                        php_module_shutdown();
@@ -664,21 +683,9 @@ any .htaccess restrictions anywhere on your site you can leave doc_root undefine
        zend_llist_destroy(&global_vars);
 
        if (!cgi) {
-               if (!SG(request_info).query_string) {
-                       for (i = ap_php_optind, len = 0; i < argc; i++)
-                               len += strlen(argv[i]) + 1;
-
-                       s = malloc(len + 1);    /* leak - but only for command line version, so ok */
-                       *s = '\0';                      /* we are pretending it came from the environment  */
-                       for (i = ap_php_optind, len = 0; i < argc; i++) {
-                               strcat(s, argv[i]);
-                               if (i < (argc - 1))
-                                       strcat(s, "+");
-                       }
-                       SG(request_info).query_string = s;
-               }
-               if (!SG(request_info).path_translated && argc > ap_php_optind)
+               if (!SG(request_info).path_translated && argc > ap_php_optind) {
                        SG(request_info).path_translated = estrdup(argv[ap_php_optind]);
+               }
        } else {
        /* If for some reason the CGI interface is not setting the
           PATH_TRANSLATED correctly, SG(request_info).path_translated is NULL.