PHP, CGI, $_GET Not Working
Posted by: Warren (---.oxqn1.cha.bigpond.net.au)
Date: November 10, 2012 09:50AM

I must be doing something wrong! I have a simple CGI script called fred.php, placed in C:\wamp\bin\apache\apache2.2.22\cgi-bin. Code is:

#!php
<?php
echo "Content-Type: text/html\n\n";
echo "<html><head></head><body>\n";
print_r($GLOBALS);
echo "</body></html>\n";
?>

The $_GET array isn't being filled in, even though $QUERY_STRING has the parameter values.

Here is the output when I enter the URL and append some CGI parameters. Any ideas why $_GET is empty? Thanks, Warren

Array ( [_GET] => Array ( ) [_POST] => Array ( ) [_COOKIE] => Array ( ) [_FILES] => Array ( ) [argv] => Array ( [0] => C:/wamp/bin/apache/apache2.2.22/cgi-bin/fred.php ) [argc] => 1 [_ENV] => Array ( ) [_REQUEST] => Array ( ) [_SERVER] => Array ( [HTTP_HOST] => localhost [HTTP_USER_AGENT] => Mozilla/5.0 (Windows NT 5.1; rv:16.0) Gecko/20100101 Firefox/16.0 [HTTP_ACCEPT] => text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 [HTTP_ACCEPT_LANGUAGE] => en-US,en;q=0.5 [HTTP_ACCEPT_ENCODING] => gzip, deflate [HTTP_CONNECTION] => keep-alive [PATH] => C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\wamp\bin\php\php5.4.3 [SystemRoot] => C:\WINDOWS [COMSPEC] => C:\WINDOWS\system32\cmd.exe [PATHEXT] => .COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH [WINDIR] => C:\WINDOWS [SERVER_SIGNATURE] => [SERVER_SOFTWARE] => Apache/2.2.22 (Win32) PHP/5.4.3 [SERVER_NAME] => localhost [SERVER_ADDR] => 127.0.0.1 [SERVER_PORT] => 80 [REMOTE_ADDR] => 127.0.0.1 [DOCUMENT_ROOT] => [SERVER_ADMIN] => admin@localhost [SCRIPT_FILENAME] => C:/wamp/bin/apache/apache2.2.22/cgi-bin/fred.php [REMOTE_PORT] => 1346 [GATEWAY_INTERFACE] => CGI/1.1 [SERVER_PROTOCOL] => HTTP/1.1 [REQUEST_METHOD] => GET [QUERY_STRING] => fred=cat&dog=jim [REQUEST_URI] => /cgi-bin/fred.php?fred=cat&dog=jim [SCRIPT_NAME] => C:/wamp/bin/apache/apache2.2.22/cgi-bin/fred.php [PHP_SELF] => C:/wamp/bin/apache/apache2.2.22/cgi-bin/fred.php [PATH_TRANSLATED] => C:/wamp/bin/apache/apache2.2.22/cgi-bin/fred.php [REQUEST_TIME_FLOAT] => 1352533794.193 [REQUEST_TIME] => 1352533794 [argv] => Array ( [0] => C:/wamp/bin/apache/apache2.2.22/cgi-bin/fred.php ) [argc] => 1 ) [GLOBALS] => Array *RECURSION* )

Options: ReplyQuote
Re: PHP, CGI, $_GET Not Working
Posted by: stevenmartin99 (Moderator)
Date: November 10, 2012 10:10AM

You didn't write get in your script!

Change GLOBALS TO GET


GLOBALS has been off since php5 began!!

Steven Martin
stevenmartin99@gmail.com
stevenmartin99@hotmail.com
PampServer.com - [pampserver.com]

Options: ReplyQuote
Re: PHP, CGI, $_GET Not Working
Posted by: stevenmartin99 (Moderator)
Date: November 10, 2012 10:10AM

You didn't write get in your script!

Change GLOBALS TO GET


GLOBALS has been off since php5 began!!

Steven Martin
stevenmartin99@gmail.com
stevenmartin99@hotmail.com
PampServer.com - [pampserver.com]

Options: ReplyQuote
Re: PHP, CGI, $_GET Not Working
Posted by: Warren (---.oxqn1.cha.bigpond.net.au)
Date: November 10, 2012 10:31AM

I originally used $_GET, but it was empty. I am printing out $GLOBALS just to see what variables do have values. Note that it shows:

[QUERY_STRING] => fred=cat&dog=jim
[_GET] => Array ( )

which means that $QUERY_STRING has something in it, but $_GET is an empty array. I can't work out how $_GET can be empty when $QUERY_STRING has a value.

Thanks, Warren

Options: ReplyQuote
Re: PHP, CGI, $_GET Not Working
Posted by: Warren (---.oxqn1.cha.bigpond.net.au)
Date: November 10, 2012 12:33PM

Some more data. If the PHP script is in C:\wamp\www, then it works and fills in $_GET. If the same script is in
C:\wamp\bin\apache\apache2.2.22\cgi-bin then the $_GET array is not filled in. OK, so I will stick with the scripts in
the \www directory for now, but I'd still like to know why there is a difference.

Cheers, Warren

Options: ReplyQuote
Re: PHP, CGI, $_GET Not Working
Posted by: stevenmartin99 (Moderator)
Date: November 10, 2012 12:59PM

Cos the document root is not in apache folder

.

Can you do a print_r of the $_SERVER array in both places


Btw You can specify the cgi bin in the httpd.conf

Steven Martin
stevenmartin99@gmail.com
stevenmartin99@hotmail.com
PampServer.com - [pampserver.com]

Options: ReplyQuote
Re: PHP, CGI, $_GET Not Working
Posted by: Warren (---.oxqn1.cha.bigpond.net.au)
Date: November 10, 2012 01:13PM

The $_SERVER array of the script in cgi-bin is included in my original post, look for [_SERVER] => Array ( .... ). Here's the output when the same script is in \www. Note that the $_GET array now has values.

Cheers, Warren

Array ( [_GET] => Array ( [fred] => cat [dog] => jim ) [_POST] => Array ( ) [_COOKIE] => Array ( ) [_FILES] => Array ( ) [_ENV] => Array ( ) [_REQUEST] => Array ( [fred] => cat [dog] => jim ) [_SERVER] => Array ( [HTTP_HOST] => localhost [HTTP_USER_AGENT] => Mozilla/5.0 (Windows NT 5.1; rv:16.0) Gecko/20100101 Firefox/16.0 [HTTP_ACCEPT] => text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 [HTTP_ACCEPT_LANGUAGE] => en-US,en;q=0.5 [HTTP_ACCEPT_ENCODING] => gzip, deflate [HTTP_CONNECTION] => keep-alive [PATH] => C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\wamp\bin\php\php5.4.3 [SystemRoot] => C:\WINDOWS [COMSPEC] => C:\WINDOWS\system32\cmd.exe [PATHEXT] => .COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH [WINDIR] => C:\WINDOWS [SERVER_SIGNATURE] => [SERVER_SOFTWARE] => Apache/2.2.22 (Win32) PHP/5.4.3 [SERVER_NAME] => localhost [SERVER_ADDR] => 127.0.0.1 [SERVER_PORT] => 80 [REMOTE_ADDR] => 127.0.0.1 [DOCUMENT_ROOT] => C:/wamp/www/ [SERVER_ADMIN] => admin@localhost [SCRIPT_FILENAME] => C:/wamp/www/fred.php [REMOTE_PORT] => 1401 [GATEWAY_INTERFACE] => CGI/1.1 [SERVER_PROTOCOL] => HTTP/1.1 [REQUEST_METHOD] => GET [QUERY_STRING] => fred=cat&dog=jim [REQUEST_URI] => /fred.php?fred=cat&dog=jim [SCRIPT_NAME] => /fred.php [PHP_SELF] => /fred.php [REQUEST_TIME_FLOAT] => 1352549434.632 [REQUEST_TIME] => 1352549434 ) [GLOBALS] => Array *RECURSION* ) Array ( [fred] => cat [dog] => jim )

Options: ReplyQuote


Sorry, only registered users may post in this forum.