Page 1 of 1
$_GET array seems to be empty
Posted: Sat Jul 26, 2003 3:57 pm
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.
I've got it to work...but a question remains
Posted: Sat Jul 26, 2003 5:24 pm
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.
Posted: Sat Jul 26, 2003 5:29 pm
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?
Posted: Sat Jul 26, 2003 5:30 pm
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.
Posted: Sat Jul 26, 2003 5:33 pm
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)?
Posted: Sun Jul 27, 2003 12:05 am
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.
Posted: Sun Jul 27, 2003 2:09 am
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>