I have an apache with a php module and it works fine. I am also trying to make it use a the cli version of php to do the same thing. I can take a working .php file with a form (post), and when I rename it to .cgi and add a #! line for php then the $_POST never has anything in it.
I am not sure what other info I should supply, or where I should look for what is going on, so I will end this here and eagerly await a helpful reply.
how do I use post variable in CLI php
Moderator: General Moderators
My scripts
The two are at:
http://www.nmt.edu/~wcolburn/p/module.php
http://www.nmt.edu~wcolburn/p/cli.cgi
The module works fine, the cgi doesn't.
-----module.php-----
<html>
<body>
<br><br>
<?=$errormessage?>
<br>
<title>Personals</title>
<h1>Personals</h1>
Welcome to my toy PHP experiment.
<?php
if ($_POST['submit'])
{
print "the form has been submitted";
$required_fields = explode(",", $_POST['required']);
$error = 0;
foreach($required_fields as $fieldname)
{
if ($_POST[$fieldname] == "")
{
$error++;
print "You are missing $fieldname!\n";
}
}
}
?>
<form action="module.php" method="post">
Your email:<input type="text" name="email"
value="<?=$_POST['email']?>"><br>
Your passphrase:<textarea name="passphrase"><?=$_POST['passphrase']?></textarea>
<br>
<input type="hidden" name="required" value="email,passphrase">
<input type="submit" name="submit" value="submit">
</form>
</body></html>
-----end module.php-----
Here is the diff between module.php and cli.cgi:
diff module.php cli.cgi
0a1,3
> #!/fermium/accounts/www/php/bin/php
> Content-type: text/html
>
33c36
< <form action="module.php" method="post">
---
> <form action="cli.cgi" method="post">
As you can see, all I did was add a line to emit the proper content-type and changed the name of the action.
http://www.nmt.edu/~wcolburn/p/module.php
http://www.nmt.edu~wcolburn/p/cli.cgi
The module works fine, the cgi doesn't.
-----module.php-----
<html>
<body>
<br><br>
<?=$errormessage?>
<br>
<title>Personals</title>
<h1>Personals</h1>
Welcome to my toy PHP experiment.
<?php
if ($_POST['submit'])
{
print "the form has been submitted";
$required_fields = explode(",", $_POST['required']);
$error = 0;
foreach($required_fields as $fieldname)
{
if ($_POST[$fieldname] == "")
{
$error++;
print "You are missing $fieldname!\n";
}
}
}
?>
<form action="module.php" method="post">
Your email:<input type="text" name="email"
value="<?=$_POST['email']?>"><br>
Your passphrase:<textarea name="passphrase"><?=$_POST['passphrase']?></textarea>
<br>
<input type="hidden" name="required" value="email,passphrase">
<input type="submit" name="submit" value="submit">
</form>
</body></html>
-----end module.php-----
Here is the diff between module.php and cli.cgi:
diff module.php cli.cgi
0a1,3
> #!/fermium/accounts/www/php/bin/php
> Content-type: text/html
>
33c36
< <form action="module.php" method="post">
---
> <form action="cli.cgi" method="post">
As you can see, all I did was add a line to emit the proper content-type and changed the name of the action.
if you're really using the cli-version then it does not support cgi.
http://www.php.net/manual/en/features.commandline.php
http://www.php.net/manual/en/features.commandline.php
It's worth mentioning that CLI and CGI are different SAPI's although they do share many of the same behaviors.