$_GET array seems to be empty

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
rhunter007
Forum Newbie
Posts: 5
Joined: Sat Jul 26, 2003 3:57 pm

$_GET array seems to be empty

Post by rhunter007 »

I am trying to test my php (version 4.3.2) + apache setup using php as a cgi.

Here is my (trival) php script:
#!/usr/local/bin/php
<?

print("Content-type: text/html\n\n");

print phpversion();
print "<p>|" . $_GET["test"] . "|<p>";
print "hello world.\n";

?>

And here is the web output when I enter the URL http://<my-domain>/cgi-bin/test.php?test=data in my browser:

4.3.2

||

hello world.


How can this be? I didn't change a thing with my php.ini. Everything was default I think. Thanks for any advice you can offer.
rhunter007
Forum Newbie
Posts: 5
Joined: Sat Jul 26, 2003 3:57 pm

I've got it to work...but a question remains

Post by rhunter007 »

So, I finally got it to work. I moved the script out of the cgi-bin and put it in htdocs. I got rid of the Content/stuff, and the call to #!/usr/local/bin/php at the top. I added html and body tags and then embedded the php in the middle...and it worked--it now has the correct $_GET array!

But now I'm totally confused. Was I not supposed to put my php script in my cgi-bin? Should I create another directory in /usr/local/apache called php-bin and put my php scripts there?

Thanks for any advice.
User avatar
nielsene
DevNet Resident
Posts: 1834
Joined: Fri Aug 16, 2002 8:57 am
Location: Watertown, MA

Post by nielsene »

I'm not sure, but the changes you made, make is sound like your php is NOT cgi, but rather the dynamic module variety. Are you sure it was compiled as cgi?
tsg
Forum Contributor
Posts: 142
Joined: Sun Jan 12, 2003 9:22 pm
Location: SE, Alabama
Contact:

Post by tsg »

I think you are confused or I am.

With PHP, you don't need to run it in a bin or anything. It will run on any and every page if you have PHP on the servers and the pages end in .php.
rhunter007
Forum Newbie
Posts: 5
Joined: Sat Jul 26, 2003 3:57 pm

Post by rhunter007 »

nielsene wrote:I'm not sure, but the changes you made, make is sound like your php is NOT cgi, but rather the dynamic module variety. Are you sure it was compiled as cgi?
Maybe not. I'll check, thanks. But as far as my new question goes, do people still put PHP scripts in the cgi-bin? Because it seems like with a script you have two choices: 1) in cgi-bin, running it as a script, where you are forced to do the "Content: text/html" stuff, or 2) not running it as a script, just as a normal web page.

Is there any disadvantage to (2)?
User avatar
nielsene
DevNet Resident
Posts: 1834
Joined: Fri Aug 16, 2002 8:57 am
Location: Watertown, MA

Post by nielsene »

Well the cgi-bin method is sometimes considered more secure. I don't agree most of the time. However it can be nice to not have static and dynamic pages scattered around your web tree.

Most people are using the web-server module version of PHP and not cgi. I run both both a web-server version and a cli version, but that seems to be uncommon around here.
User avatar
m3mn0n
PHP Evangelist
Posts: 3548
Joined: Tue Aug 13, 2002 3:35 pm
Location: Calgary, Canada

Post by m3mn0n »

heh, is seems like your trying to run a perl script. ;) You aren't a perl coder, are you?

1. PHP never requires you to located the php dir
2. PHP can run on any folder on the web server
eg. localhost/index.php
3. If you have an html page, you dont need to echo headers telling php is there, just open and close tags accordingly and make sure the file type is php recognized, eg.

Code: Select all

<?php
$bgcolor = "white";
$text = "black";
$title = "my first page";
$myvariable = "Hello, World!\n\n";
?>
<html>
<head>
<title><?=$title?></title>
</head>
<?php echo "<body bgcolor=".$bgcolor." text=".$text." link="red">";
echo $myvariable;
echo "<br><br><center>This text is php processed!</center>";
?>
</body>
</html>
Post Reply